Reputation: 427
I've searched for an answer to this all over but couldn't find what i'm really looking for! so i had to ask here..
i don't know how to explain this but here is a table :
Date BL Client Design Ref1 Ref2 Ref3 Qte
14/01/2013 13011401 A VT VT1 JAUNE XL 3
14/01/2013 13011402 B VT VT2 GRIS L 30
16/01/2013 13011601 D VT VT1 GRIS L 10
16/01/2013 13011602 C VT VT2 GRIS L 32
19/01/2013 13011903 F VT VT2 JAUNE L 15
i'm looking for a result that could look like the following:
Date BL Client Design Ref1 Ref2 Ref3 Qte
14/01/2013 13011401 A VT VT1 JAUNE XL 3
14/01/2013 13011402 B VT VT2 GRIS L 62
16/01/2013 13011601 D VT VT1 GRIS L 10
19/01/2013 13011903 F VT VT2 JAUNE L 15
edit: sum Qte if there is a duplicate (Design,Ref1, Ref2, Ref3)
don't know if this is possible but i would appreciate your help!
Upvotes: 1
Views: 87
Reputation: 4629
Try this
SELECT *,
Sum(field_name)
FROM tablename
GROUP BY column_name
Upvotes: 0
Reputation: 18
SELECT *, SUM(field) FROM table GROUP BY field
Apply the aggregare function i.e SUM on the field whose sum is required to you and then Group By the same.....
Upvotes: 0
Reputation: 4888
table : mytable
col1 col2 Col3 col4 col5 col7 col8 col9
14/01/2013 13011401 A VT VT1 JAUNE XL 3
14/01/2013 13011402 B VT VT2 GRIS L 30
16/01/2013 13011601 D VT VT1 GRIS L 10
16/01/2013 13011602 C VT VT2 GRIS L 32
19/01/2013 13011903 F VT VT2 JAUNE L 15
What I understood is that You want duplicate on the basis of col4,col5,col7,col8
for this you can do like
SELECT col1,col2,Col3,col4,col5,col7,col8,SUM(col9)
FROM mytable
GROUP BY col4,col5,col7,col8;
In this group by will always return first row for other fields
Upvotes: 1
Reputation: 9008
you are looking for something like
SELECT *, SUM(field) FROM table
GROUP BY field1, field2
where field is the column that you want to sum and field1 and field2 are the columns you want to group
Upvotes: 0