Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
have a table t1 amount class 100 A200 B230 C233 A400 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/pSrinika
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2007-01-29 : 16:50:34
SELECT class, SUM(amount)FROM YourTableGROUP BY classTara Kizer
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 @t1select 100, 'A' union allselect 200, 'B' union allselect 230, 'C' union allselect 233, 'A' union allselect 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*/