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
 General SQL Server Forums
 New to SQL Server Programming
 sum

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2014-07-07 : 22:01:34
i did a union to query out the count on baggage and customer.
the first 2 row are from first query, the 3rd and 4th row are from second query.

category status country baggage adult child
adult board AUS 100KG 0 0
child board AUS 101KG 0 0
board 90 9
missing 18 1

how can i sum all together? i tried sum but it still come out the same.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-07-08 : 00:05:29
Here's one way - using a derived table

select <cols>, sum(<otherCol>)
from
(
<query1>
union all
<query2>
) as d
group by <cols>


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -