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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Sum rows

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2005-01-20 : 12:11:28
I have a table looks like:

Id High Low
A 100 50
B 250 78
C 300 56
D 120 88
E 176 43


I want to generate the output looks like:


Id High Low
A 100 50
B 250 78
Other(C+D+E) 596 187

Thanks!




AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-01-20 : 12:23:53
Is this what you want

SELECT (CASE WHEN Id IN ('A','B') THEN Id ELSE 'Other' END) AS Id, SUM(High) AS High, SUM(Low) AS Low
FROM MyTable
GROUP BY (CASE WHEN Id IN ('A','B') THEN Id ELSE 'Other' END)
Go to Top of Page
   

- Advertisement -