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
 .NET Inside SQL Server (2005)
 Sum of two queries

Author  Topic 

sreekanth939
Starting Member

12 Posts

Posted - 2009-04-23 : 03:06:18
sum of two Queries
i acn use
select a,b,c from ABC
unoin
select a,b,c from DEF

is there any method other than following. to ADD values of above queris ..
ie 1ineed output in a+a,b+b,c+c
iget result by

select sum(t.a),sum(t.b),sum(t.c) from(select a,b,c from ABC
unoin
select a,b,c from DEF
)as t

and select a+(select a from DEF),b+(select b from DEF),c+(select c from DEF) from ABC

but above two is query gives result but in my case its not correct help me pls?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-23 : 03:09:00
[code]SELECT SUM(A),
SUM(B),
SUM(C)
FROM (
SELECT SUM(A) AS A,
SUM(B) AS B,
SUM(C) AS C
FROM Table1

UNION ALL

SELECT SUM(A) AS A,
SUM(B) AS B,
SUM(C) AS C
FROM Table2
) AS d[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -