mssql如何把两个查询合并成一个

sql语句1:select count(Azcount) as 新 from StatisticsInfon

where addtime between '2012-11-14 00:00:00' and '2012-11-14 23:59:59'

sql语句2:select count(Azcount) as 旧 from StatisticsInfon

where addtime between '2012-11-13 00:00:00' and '2012-11-13 23:59:59'

用union合并之后,只能显示一列。

如何变成这种一个结果集的效果?

新 旧

12 12

慕码人8056858
浏览 891回答 3
3回答

胡子哥哥

select  sum(case when addtime between '2012-11-13 00:00:00' and '2012-11-13 23:59:59' then 1 else 0 end) as 旧,sum(case when addtime between '2012-11-14 00:00:00' and '2012-11-14 23:59:59' then 1 else 0 end) as 新 from StatisticsInfon

三国纷争

select count(Azcount) as 新, ( select count(Azcount) as 旧 from StatisticsInfon where addtime between '2012-11-13 00:00:00' and '2012-11-13 23:59:59' )from StatisticsInfon where addtime between '2012-11-14 00:00:00' and '2012-11-14 23:59:59'

繁星点点滴滴

SELECT  *FROM    ( SELECT    COUNT(*) 新          FROM      StatisticsInfon          WHERE     xxxx        ) a ,        ( SELECT    COUNT(*) 旧           FROM      StatisticsInfon          WHERE     xxxxxx         ) b
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

SQL Server