dingleberry
Programmer
I am embarrassed to ask - I just can't figure this dumb question out. I have a table. In that table I have Store, Department, UPC, Description, Retail $. This table has like 15K records in it.
I am trying to write a query that will return the top 5 (sorted descending on Retail $) for each department.
Right now, when I run the query, because it's pulling the top 5 overall, I'm just getting 15 records from one department as shown.
Store Dept UPC Description Retail $
2032 BAKERY 73314720166 BREAD PUMPERNICKLE BLK $98.67
2032 BAKERY 73314723819 SL PIE 8IN APPLE $89.85
2032 BAKERY 73314723943 BREAD CHEEZY GARLIC $55.86
2032 BAKERY 73314723575 BUN HAMBURGER WHEAT $54.91
2032 BAKERY 73314723823 SL PIE 8IN PUMPKN $53.91
I would like this but also I would like the same data for PRODUCE, GROCERY, DAIRY, DELI etc.
The sql suntax appears as follows:
SELECT TOP 5 shrink.Store, shrink.Dept, shrink.UPC, shrink.Description, shrink.[Retail $ ]
FROM shrink
WHERE (((shrink.Store)=2032))
ORDER BY shrink.Dept, shrink.[Retail $ ] DESC;
Can this be done without running a seperate query for each department? Thanks!
I am trying to write a query that will return the top 5 (sorted descending on Retail $) for each department.
Right now, when I run the query, because it's pulling the top 5 overall, I'm just getting 15 records from one department as shown.
Store Dept UPC Description Retail $
2032 BAKERY 73314720166 BREAD PUMPERNICKLE BLK $98.67
2032 BAKERY 73314723819 SL PIE 8IN APPLE $89.85
2032 BAKERY 73314723943 BREAD CHEEZY GARLIC $55.86
2032 BAKERY 73314723575 BUN HAMBURGER WHEAT $54.91
2032 BAKERY 73314723823 SL PIE 8IN PUMPKN $53.91
I would like this but also I would like the same data for PRODUCE, GROCERY, DAIRY, DELI etc.
The sql suntax appears as follows:
SELECT TOP 5 shrink.Store, shrink.Dept, shrink.UPC, shrink.Description, shrink.[Retail $ ]
FROM shrink
WHERE (((shrink.Store)=2032))
ORDER BY shrink.Dept, shrink.[Retail $ ] DESC;
Can this be done without running a seperate query for each department? Thanks!