联合查询总数怎样使查询结果为一条数据

pjw001 2010-03-10 09:46:30
如我要查询
select count(*) as aa from 表A where A=1 and B=100 查询A=1 和B=100共有多少条数据
select count(*) as bb from 表A where A=1 and B=100 and C<>'' 查询A=1 和B=100 and c<>'' 共有多少条数据
如果aa有30条bb有10条怎样使查询结果为
aa bb
30 10

而不是二条数据
30
10
...全文
62 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
pjw001 2010-03-10
  • 打赏
  • 举报
回复
不好意思先给的先得分呵呵。分不高谢谢各位了
xiaoliaoyun 2010-03-10
  • 打赏
  • 举报
回复

SELECT A.aa,B.bb FROM
(select count(*) as aa from 表A where A=1 and B=100)A
,(select count(*) as bb from 表A where A=1 and B=100 and C <>'')B
东那个升 2010-03-10
  • 打赏
  • 举报
回复
,sum(case when A=1 and B=100 and C <>'' then 1 else 0 end ) as bb

丢了when
东那个升 2010-03-10
  • 打赏
  • 举报
回复
select sum(case when A=1 and B=100 then 1 else 0 end ) as aa
,sum(case A=1 and B=100 and C <>'' then 1 else 0 end ) as bb
from 表A
sql_db 2010-03-10
  • 打赏
  • 举报
回复
select count(*) as aa,sum(case when C <>'' then 1 else 0 end) as bb from 表A where A=1 and B=100
sql_db 2010-03-10
  • 打赏
  • 举报
回复
select count(*) as aa,sum(case when C <>' then 1 else 0 end) as bb from 表A where A=1 and B=100 
feixianxxx 2010-03-10
  • 打赏
  • 举报
回复
select aa=(select count(*)from 表A where A=1 and B=100 ),
bb=(select count(*) as bb from 表A where A=1 and B=100 and C <>'')

22,294

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧