How to combine two rows of the same piece but add quantities?

I have a table "PICKITEM"

PARTID      QTY
A           1
A           3
B           11
C           8
D           5
D           3

      

I need a select statement that will return one row for similar PARTIDs and add the qty field together, but also return the rest of the rows in the table, like

PARTID      QTY
A           4
B           11
C           8
D           8

      

Probably a newb question, but I'm new to SQL syntax and queries. Any help in getting me on the right track would be appreciated!

+2


source to share


2 answers


SELECT partid, SUM( qty ) As 'qty' FROM pickitem GROUP BY partid;

      



very simple syntax, no concatenation required.

+4


source


Read the manual for GROUP BY



SELECT PARTID, SUM(QTY)
FROM PICKITEM
GROUP BY PARTID

      

0


source







All Articles