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
 one group vs others

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2007-01-29 : 16:00:35
have a table t1

amount class
100 A
200 B
230 C
233 A
400 E
-----

Want to get the summation of amount by class A vs. other classes (B C D E .... in total).
and i only have select right to sql sever.
How can i fufill that?
Thanks.

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2007-01-29 : 16:47:15
What is Class A Vs. .... ?

Give the expected o/p

Srinika
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-01-29 : 16:50:34
SELECT class, SUM(amount)
FROM YourTable
GROUP BY class

Tara Kizer
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-01-29 : 20:09:47
this ?

declare @t1 table
(
amount int,
class char(1)
)
insert into @t1
select 100, 'A' union all
select 200, 'B' union all
select 230, 'C' union all
select 233, 'A' union all
select 400, 'E'

select sum(case when class = 'A' then amount else 0 end) as [Sum of A],
sum(case when class <> 'A' then amount else 0 end) as [Sum of Others]
from @t1

/*
Sum of A Sum of Others
----------- -------------
333 830
*/




KH

Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-01-30 : 14:32:05
THX
Go to Top of Page
   

- Advertisement -