I have a table called RPT with the following columns:
CODENUMBERAXSUBGROUPITEMSTRUCTUREUNITSSOLDDOLLARS
I need to return to the user the TOP 20 AXSUBGROUPS based on UNITSSOLD along with the UNITSSOLD and DOLLARS values. In addition, I need to return the ITEMSTRUCTURES that belong to these top 20 AXSUBGROUPS (joined by codenumber), along with their UNITSSOLD AND DOLLARS.
I'm not sure which way to go about querying this as I need to group by AXSUBGROUP and then by ITEMSTRUCTURE but ITEMSTRUCTURE is tied to aXSUBGROUP by CODENUMBER.
I'd appreciate any help you can give.
Thank you.
EDIT To better illustrate my needs:
- BAR - 10,000
- BAR 2 oz - 5,000
- BAR 1 oz - 5,000
- GIFT BOX - 8,000
- TRUFFLE BOX - 5,000
- ACRYLIC BOX - 3,000
...
Here's sample data in the table (sorry - couldn't figure out how to format a table...)
CodeNumber UnitsSold Dollars AxSubGroup ItemStructure
ABC123 | 9 | 500 | Bar | 1 oz
ABC456 | 9 | 800 | Bar | 2 oz
ABC789 | 9 | 500 | Bar | 3 oz
DEF123 | 3 | 200 | Tin | Round
DEF456 | 2 | 200 | Tin | Rectangular
GHI123 | 1 | 200 | Truffle | Luxe
GHI456 | 5 | 100 | Truffle | Executive
GHI789 | 4 | 200 | Truffle | Eco
JKL123 | 9 | 500 | Box | 2 pc
JKL456 | 5 | 100 | Box | 4 pc
JKL789 | 5 | 100 | Box | 8 pc
... If it helps, originally this was 2 tables - RPT (CodeNumber, UnitsSold, Dollars) and FLEX (CodeNumber, AxSubGroup, ItemStructure).