Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create Select Group By (on huge table)
Message
From
28/09/2005 10:48:14
 
 
To
27/09/2005 21:37:07
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01053729
Message ID:
01053958
Views:
5
>My table fields are...
>cClass
>cSku
>cSupplier
>cStyle
>cCost
>cRetail
>nSalesQty
>
>Table has 23 millions of records, then I need to create the best query. My query needs all fields in SELECT... a SUM on nSalesQty and GROUP BY cClass and cSku. My question is: how can I extract in the same query (or otherwise) all the rest of fields (cSupplier, cStyle, cCost, cRetail), because other fields are not aggregate. Do I need to use MAX(cSupplier), MAX(cStyle)... etc ? Or there is another way to do that? Don't forget my table is very huge.
SELECT *,GG.SUMX FROM TABLE TT
JOIN (SELECT SUM(nSalesQty),MIN(pk) minpk SUMX FROM TABLE GROUP BY cClass,cSku) GG 
ON TT.pk=GG.minpk
Previous
Reply
Map
View

Click here to load this message in the networking platform