I am trying to find a way to report the unique items in a column, how many times it appears, and sum the Qty for each.
I have
Part_No,Qty
123AA,5
345BB,20
678AB,40
123AA,20
...and am looking to output like:
123AA,2,25
345BB,1,20
678AB,1,40
from another post I found that the following will give me unique and sum, but not count?!
Any assistance would be greatly appreciated.
I have
Part_No,Qty
123AA,5
345BB,20
678AB,40
123AA,20
...and am looking to output like:
123AA,2,25
345BB,1,20
678AB,1,40
from another post I found that the following will give me unique and sum, but not count?!
Code:
SELECT C.Part_No, Sum(C.Qty) AS Total, T2.N
FROM
(SELECT T.Part_No, Count(T.Part_No) AS N
FROM
(SELECT DISTINCT Part_No, Count(*) AS N
FROM Form_Data GROUP BY Part_No) AS T
GROUP BY T.Part_No) AS T2
INNER JOIN Form_Data AS C
ON T2.Part_No = C.Part_No
GROUP BY C.Part_No, T2.N;
Any assistance would be greatly appreciated.
Comment