A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Multiple ranks per record based on different fields.



 
 
Thread Tools Display Modes
  #1  
Old May 25th, 2004, 07:41 PM
Looney
external usenet poster
 
Posts: n/a
Default Multiple ranks per record based on different fields.

OK,

I have a table of clients, the primary key is their FilerID, then Name, Address, City, State, Zip, and Volume. I need to rank their volume based on nationwide, city, state, and zip. So xyz company is 30th in the nation, 10 in TX, 5th in Austin, and 1st in 77750. There are about 30,000 records, I was able to rank them nationwide in excel, but when trying to rank by city/state/zip, the reference cells change on resorts and skew the rankings.

Any help would be appreciated...
  #2  
Old May 26th, 2004, 01:30 PM
Gary Walter
external usenet poster
 
Posts: n/a
Default Multiple ranks per record based on different fields.


"Looney" wrote in message
...
OK,

I have a table of clients, the primary key is their FilerID, then Name, Address,

City, State, Zip, and Volume. I need to rank their volume based on nationwide, city,
state, and zip. So xyz company is 30th in the nation, 10 in TX, 5th in Austin, and
1st in 77750. There are about 30,000 records, I was able to rank them nationwide in
excel, but when trying to rank by city/state/zip, the reference cells change on
resorts and skew the rankings.

Hi Looney,

I think you want something like:
(untested)

SELECT
t1.[Name],
t1.Address,
t1.City,
t1.State,
t1.Zip,
t1.Volume,
(SELECT COUNT(*)
FROM yourtable as t2
WHERE t2.Volume t1.Volume) + 1 AS NationRank,
(SELECT COUNT(*)
FROM yourtable as t3
WHERE t3.Volume t1.Volume
AND
t3.State = t1.State ) + 1 AS StateRank,
(SELECT COUNT(*)
FROM yourtable as t4
WHERE t4.Volume t1.Volume
AND
t4.City = t1.City ) + 1 AS CityRank,
(SELECT COUNT(*)
FROM yourtable as t5
WHERE t5.Volume t1.Volume
AND
t5.Zip = t1.Zip ) + 1 AS ZipRank
FROM yourtable as t1


Hopefully that will get you started.

Good luck,

Gary Walter


  #3  
Old May 26th, 2004, 02:01 PM
Gary Walter
external usenet poster
 
Posts: n/a
Default Multiple ranks per record based on different fields.

"Looney" wrote
OK,

I have a table of clients, the primary key is their FilerID, then Name, Address,

City, State, Zip, and Volume. I need to rank their volume based on nationwide, city,
state, and zip. So xyz company is 30th in the nation, 10 in TX, 5th in Austin, and
1st in 77750. There are about 30,000 records, I was able to rank them nationwide in
excel, but when trying to rank by city/state/zip, the reference cells change on
resorts and skew the rankings.

Hi Looney,

I think you want something like:
(untested)

SELECT
t1.[Name],
t1.Address,
t1.City,
t1.State,
t1.Zip,
t1.Volume,
(SELECT COUNT(*)
FROM yourtable as t2
WHERE t2.Volume t1.Volume) + 1 AS NationRank,
(SELECT COUNT(*)
FROM yourtable as t3
WHERE t3.Volume t1.Volume
AND
t3.State = t1.State ) + 1 AS StateRank,
(SELECT COUNT(*)
FROM yourtable as t4
WHERE t4.Volume t1.Volume
AND
t4.City = t1.City ) + 1 AS CityRank,
(SELECT COUNT(*)
FROM yourtable as t5
WHERE t5.Volume t1.Volume
AND
t5.Zip = t1.Zip ) + 1 AS ZipRank
FROM yourtable as t1


Hopefully that will get you started.

Good luck,

Gary Walter



  #4  
Old May 27th, 2004, 06:46 PM
Looney
external usenet poster
 
Posts: n/a
Default Multiple ranks per record based on different fields.

Thanks for your response, I will give it a shot.
  #5  
Old May 28th, 2004, 11:31 PM
Looney
external usenet poster
 
Posts: n/a
Default Multiple ranks per record based on different fields.

Gary, you rock.

That did the trick alright. And now that I have an idea of what to do I can apply it to several other queries I need to do. I really appreciate your help.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:31 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.