paulostrom
Programmer
Suppose I have a table with the fields "location", daily_sales", and "date". There are 3 different locations and I want the Top 3 "daily_sales" for each location.
I know this can easily be done using separate queries for each location (i.e., Select Top 3 Daily_Sales from Sales where location = "A" Order By Daily_Sales DESC). Unfortunately, there are actually thousands of "locations" in my database and using separate queries doesn't seem to be very scalable.
I've made various attempts using grouping, query of queries, and nested queries but can't seem to get the results I need. This seems like a simple enough problem and I'm hoping there is a simple solution that I am just overlooking. Any suggestions would be greatly appreciated.
I know this can easily be done using separate queries for each location (i.e., Select Top 3 Daily_Sales from Sales where location = "A" Order By Daily_Sales DESC). Unfortunately, there are actually thousands of "locations" in my database and using separate queries doesn't seem to be very scalable.
I've made various attempts using grouping, query of queries, and nested queries but can't seem to get the results I need. This seems like a simple enough problem and I'm hoping there is a simple solution that I am just overlooking. Any suggestions would be greatly appreciated.