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 2005 Forums
 Transact-SQL (2005)
 substract sum fields

Author  Topic 

mimic
Starting Member

18 Posts

Posted - 2007-08-30 : 09:01:23
Hi!

I have the following problem.
I'd like to substract two agregate fields like:

select aa, (SUM(field1)-SUM(field2)) as "something" from table1 group by aa

so i need a calculated value that would sumerize filed1, sumerize field2
and than substract those values for each value in field aa.
Can enyone help?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-08-30 : 09:03:16
[code]select aa, SUM(field1), SUM(field2), SUM(field1) - SUM(field2) as [something]
from table1
group by aa[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -