Multiple Rankings in 1 Query

dmarek

New Member
Joined
Mar 26, 2010
Messages
21
So I have a database with several tables containing metrics. I group these metrics up into 1 query through a few steps (which is fine).

What I want to do next is create a point system using each Stores rank for each metric from best to worst.

Example:

Store Sales $ Target $ Variance to Target $
1234 $1000 $1500 ($500)

similar setup for 4 other metrics, actual->target->variance.

I want to rank each of the 5 metrics to get a score (which I can do individually in separate queries) then add them together and order by worst to best.

Ideas?


PS My method for doing them individually is something like this:

SELECT table.store,
table.variance,
(SELECT count(*) FROM table AS t1 WHERE table.variance > t1.variance) as RANK_SALES_VAR
FROM table
GROUP BY table.store, table.variance
ORDER BY table.variance asc;

I am trying to take that concept (which works) but instead of having 5 side queries to build 1 master RANK query do them in 1 swoop.

Reason for wanting to do it in as few steps as possible is because i have several rankings to do hierarchical. Meaning Store->District->Region and for different businesses of the company.

Thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I do not believe you can do it all in one query. To do it in one query you may need to create a function to do it instead.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top