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
 SQL Server Development (2000)
 Sum Query

Author  Topic 

shanepj
Starting Member

4 Posts

Posted - 2006-01-24 : 17:03:42
I have two tables that both hold cpucount information for inventory. I need to run a query that simply gives me a total cpu count from both tables. Both of the following statements work for the sum of each individual table. I just need to get the total of both as in a "Grand Total" of CPU count.

Select
'Server Total' as CPUtotal, sum (sdw.srvcpucount) as total

From server sdw

------
Select
'Unix Total' as CPUtotal, sum (ud.unxcpucount) as total

From unix ud


Cyclonik
Posting Yak Master

114 Posts

Posted - 2006-01-24 : 17:13:25
select (select sum (sdw.srvcpucount) From server) + (Select sum(ud.unxcpucount) from unix)) as Grand Total



Go to Top of Page

Cyclonik
Posting Yak Master

114 Posts

Posted - 2006-01-24 : 17:27:44
select sum(total) from
(select sum (sdw.srvcpucount) as total From server
UNION ALL
Select sum(ud.unxcpucount) as total from unix) a

This might work too.
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2006-01-24 : 17:45:23
And yet another way...

Select sdwTotal, udTotal, sdwTotal + udTotal As GrandTotal
FROM (
select (select sum (sdw.srvcpucount) From server) As sdwTotal, (Select sum(ud.unxcpucount) from unix) As udTotal
) X
Go to Top of Page
   

- Advertisement -