>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