Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SELECT grouping

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2007-09-16 : 11:06:59
If I have a table which as the following columns/data

item boxes quantity
---- ----- --------
CH 20 16
CH 10 20
CH 15 16

how can I get all the CH items so that they are grouped by quantity and the boxes are totalled to give:

CH 35 16
10 20

please?

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-09-16 : 11:16:37
select item, sum(boxes), quantity
from yourtable
group by item, quantity

Every row will and should return the item; to suppress the duplicates or create a group header on item, you would do this at your client report, web page, or application.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page
   

- Advertisement -