![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
325000 MotorBikes | Cruiser | TR-1300 | 1 190000 MotorBikes | OffRoad | KLR-250 | 1 100000 MotorBikes | OffRoad | KLR-500 | 2 27000 QuadBikes | DuneKiller | 5.7L | 1 275000 QuadBikes | GrassHopper | 500cc | 1 | |
|
15000 |
#2
| |||
| |||
|
|
Hi Everyone, I have typically not bothered with this particular branch of SQL programming but would like to ask for some guidance on solving a problem. I can certainly mimic a solution I find on the web, but I would like to understand the mechanics of the solution so that I can properly adapt it and have so far not found a suitable explanation. The scenario is simply this: I have a table with four columns (for example). I need to generate a ranking report for the data in these columns, and restart the ranking based on the value of one of the columns. For example: Category | SubCategory | Product | SalesValue MotorBikes | Off-Road | KLR-250 | 100000 MotorBikes | Off-Road | KLR-500 | 27000 MotorBikes | Cruiser | TR-1300 | 190000 QuadBikes | GrassHopper | 750cc | 15000 QuadBikes | GrassHopper | 500cc | 122000 QuadBikes | DuneKiller | 5.7L | 275000 MotorBikes | CafeRacer | Desmo | 325000 The desired output would be to have the data ranked by sales value for each product per category, per subcategory. So the output would look like this: Category | Subcategory | Product | Rank | Sales Value MotorBikes | CafeRacer | Desmo | 1 325000 MotorBikes | Cruiser | TR-1300 | 1 190000 MotorBikes | OffRoad | KLR-250 | 1 100000 MotorBikes | OffRoad | KLR-500 | 2 27000 QuadBikes | DuneKiller | 5.7L | 1 275000 QuadBikes | GrassHopper | 500cc | 1 | 122000 QuadBikes | GrassHopper | 750cc | 2 15000 This is a fairly typical use scenario I guess, but so far I have reliaed on other systems to perform the ranking functions (such as BI systems, PIVOT type products etc...) and not ever implemented this myself. I want to change that oversight on my part and fill the knowledge gap. Can you help me? |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Bob, Thanks for the walkthrough. I appreciate it. Having a tied set of values doesnt matter for the ranking as if I understand the SQl correctly then it should give them all the same rank, and then the next 'lowest' score would be a jump down in rank by the normal increment of one for each of the 'regular' results, and also one for each of the tied results. This might mean that I have three results at rank 7 and then the next value for rank for the next item that is not a tie would be rank 10. Does that stand to reason? Did I understand it correctly? Yes, you've got it. |
|
Do you find that the correlated subquery is slow to run in your experience? I've never tried it against a large enought data set to make performance an |
| ps: Yours is the first explanation has actually made sense to me. Thankyou for sharing. |
#5
| |||
| |||
|
|
Hi Everyone, I have typically not bothered with this particular branch of SQL programming but would like to ask for some guidance on solving a problem. I can certainly mimic a solution I find on the web, but I would like to understand the mechanics of the solution so that I can properly adapt it and have so far not found a suitable explanation. The scenario is simply this: I have a table with four columns (for example). I need to generate a ranking report for the data in these columns, and restart the ranking based on the value of one of the columns. For example: * * Category *| * SubCategory * *| * *Product * *| * *SalesValue MotorBikes *| * *Off-Road * * * *| * *KLR-250 * *| * *100000 MotorBikes *| * *Off-Road * * * *| * *KLR-500 * *| * * 27000 MotorBikes *| * *Cruiser * * * * *| * *TR-1300 * * | * *190000 QuadBikes * | * GrassHopper *| * *750cc * * * *| * *15000 QuadBikes * | * GrassHopper *| * *500cc * * * *| * *122000 QuadBikes * | * DuneKiller * * *| * *5.7L * * * * * | * *275000 MotorBikes *| * CafeRacer * * *| * * Desmo * * *| **325000 The desired output would be to have the data ranked by sales value for each product per category, per subcategory. So the output would look like this: * * Category * *| * *Subcategory * *| * *Product * *| * *Rank * *| Sales Value MotorBikes * *| * *CafeRacer * * * *| * *Desmo * * | * 1 | * * 325000 MotorBikes * *| * *Cruiser * * * * * *| * * TR-1300 * | * 1 | * * 190000 MotorBikes * *| * *OffRoad * * * * * | * *KLR-250 * | * *1 | * * *100000 MotorBikes * *| * *OffRoad * * * * * | * *KLR-500 * | * *2 | * * *27000 QuadBikes * *| * *DuneKiller * * * *| * *5.7L * ** * | * *1 | * * 275000 QuadBikes * *| * *GrassHopper * *| * *500cc * * *| * * 1 * * * * | 122000 QuadBikes * *| * *GrassHopper * *| * *750cc * * *| * * 2 | * * *15000 This is a fairly typical use scenario I guess, but so far I have reliaed on other systems to perform the ranking functions (such as BI systems, PIVOT type products etc...) and not ever implemented this myself. I want to change that oversight on my part and fill the knowledge gap. Can you help me? Cheers The Frog |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
As I said I typically use other tools for the Rank function. Oracle has a similar capability, SQL Server, and many other tools used in BI too. This is not actually for an access project but a simple extension for an Excel macro that is better done in temporary DB than in Excel itself. A bit of DAO and you avoid hideous amounts of VBA looping which is extremely slow, as well as having to use Excels row / column data handling which is also extremely slow. This process just isnt worth dumping into a full DB solution as it is ad-hoc used, small scale, and non critical, and department limited. For comparison the Rank function in both SQL Server and Oracle operates about 1000x faster than the SQL done in Jet. Cheers The Frog |
#8
| |||
| |||
|
#9
| |||
| |||
|
|
If you have SQL Server and a Web Server to work with. If you dont, you cant. ADP is also completely useless inside of a macro in Excel - they have nothing to do with each other; and therefore cannot solve this problem. FWIW if I were to create a web page based solution I would either create a Java based solution and deploy it via Tomcat, or a simpler PHP / MySQL approach. ADP is kiddie stuff to me and reeks of amateurism. If you want to do web development properly then learn to code properly in Web standards - of which ADP is not a part. The Frog |
#10
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |