Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
Hi,

I want to truncate duplicate rows 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 the result like,
Item   Qty   MinQty   MaxQty
ABC	25    20        50
XYZ     12    30        40


Kindly help me to write the query for the same...
Posted
Updated 30-Jul-13 3:24am
v3

SQL
Select Item, sum(Qty) as Qty, MinQty, MaxQty
from <your table>
Group by Item, MinQty, MaxQty
 
Share this answer
 
v2
Comments
Maciej Los 30-Jul-13 9:25am    
+5
The following statement will work by using a GROUP BY[^] clause:

[Edit]As Maciej pointed out the Qty column needed to be removed from the group by clause.[/Edit]
SQL
SELECT tab.Item, SUM(tab.Qty) as Qty, tab.MinQty, tab.MaxQty
FROM   WhatEverNameYourtTableMayHave as tab
GROUP BY tab.Item, tab.MinQty, tab.MaxQty


MinQty and MaxQty will have to be the same though four each discrete item.

Regards,
— Manfred
 
Share this answer
 
v3
Comments
Maciej Los 30-Jul-13 9:52am    
Are you shure that Qty shold be in GROUP BY list?
Manfred Rudolf Bihy 30-Jul-13 10:18am    
Errhmm no! Sorry I didn't really think about it when I wrote that down.

My bad!
Manfred Rudolf Bihy 30-Jul-13 10:24am    
Corrected my solution, thanks for pointing it out!

Cheers!
Maciej Los 30-Jul-13 12:02pm    
You're welcome, Manfred ;)
Now, answer deserved for 5!
Thanks for ur kind reply, ur query working fine for me.. i was looking for dat result. u guys saved my time.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900