Eliminate duplicate records in sql

I want to trim duplicate lines, but Qty should be added.

I have a table filled with data,

 Item Qty MinQty MaxQty ABC 10 20 50 XYZ 12 30 40 ABC 15 20 50 

I want to get the result, for example,

 Item Qty MinQty MaxQty ABC 25 20 50 XYZ 12 30 40 

Please help me write a request for the same ...

+4
source share
2 answers
 SELECT Item, SUM(Qty), MIN(MinQty), MAX(MaxQty) FROM tablename GROUP BY ITem; 
+9
source

The correct answer, but you must also specify the names of the derived columns:

 SELECT Item, SUM(Qty) as Qty, MIN(MinQty) as MinQty, MAX(MaxQty) as MaxQty FROM tablename GROUP BY ITem; 
+3
source

Source: https://habr.com/ru/post/1494283/


All Articles