浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Hi I have the following union query that retrieves two counts. Can I
sum them up within this query, like wrap this in a sum function
somehow to get the total count? Or is there a better way to do this.
Please help. Using SQL 2000.



select count(user_id) from table1
UNION
select count(user_id) from table2

 

 

 

==========================================

 

If you want the latter, just the sum of the counts,
here is a possibility:

select
(select count(user_id) from table1)
+ (select count(user_id) from table2)
as totalCount

If you need to count user_id values only once when
they appear in both table1 and table2, you can do this:

select count(user_id)
from (
select user_id from table1
union
select user_id from table2
) T

posted on 2009-02-16 09:18  浙林龙哥  阅读(256)  评论(1编辑  收藏  举报