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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 one group vs others
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

166 Posts

Posted - 01/29/2007 :  16:00:35  Show Profile  Reply with Quote
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?

Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 01/29/2007 :  16:47:15  Show Profile  Reply with Quote
What is Class A Vs. .... ?

Give the expected o/p

Go to Top of Page

Almighty SQL Goddess

38200 Posts

Posted - 01/29/2007 :  16:50:34  Show Profile  Visit tkizer's Homepage  Reply with Quote
SELECT class, SUM(amount)
FROM YourTable
GROUP BY class

Tara Kizer
Go to Top of Page

In (Som, Ni, Yak)

17689 Posts

Posted - 01/29/2007 :  20:09:47  Show Profile  Reply with Quote
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


Go to Top of Page

Posting Yak Master

166 Posts

Posted - 01/30/2007 :  14:32:05  Show Profile  Reply with Quote
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000