sql语句写法

nitaiyoucala 2012-03-14 11:24:37
下面这三个sql语句怎么合并成一个啊? 在一张表里面显示, 这三个sql语句的条件不同

select count(*) 搜索任务 from hy_Info where hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) group by sys_auserid

select count(*) 网盟任务 from hy_Info where hy_info_menuid in(24,25,26,27,33,34,35,36,37,38,39,40,41) group by sys_auserid

select count(*) 流程任务 from hy_Info where hy_info_menuid in(43,45,47,48,49,50,51,52,54,55,56,57,92,96,123) group by sys_auserid
...全文
94 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
David8977 2012-03-14
  • 打赏
  • 举报
回复
select count(*) 搜索任务 from hy_Info where hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) group by sys_auserid
union
select count(*) 网盟任务 from hy_Info where hy_info_menuid in(24,25,26,27,33,34,35,36,37,38,39,40,41) group by sys_auserid
union
select count(*) 流程任务 from hy_Info where hy_info_menuid in(43,45,47,48,49,50,51,52,54,55,56,57,92,96,123) group by sys_auserid
nitaiyoucala 2012-03-14
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zhaowenzhong 的回复:]
SQL code

select a.[搜索任务],b.[网盟任务],c.[流程任务] from
(select row_number() over(order by hy_info_menuid) rn,count(*) 搜索任务 from hy_Info where hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21……
[/Quote]


错了
Felixzhaowenzhong 2012-03-14
  • 打赏
  • 举报
回复
select a.[搜索任务],b.[网盟任务],c.[流程任务] from  
(select row_number() over(order by hy_info_menuid) rn,count(*) 搜索任务 from hy_Info where hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) group by sys_auserid)a
inner join
(select row_number() over(order by hy_info_menuid) rn,count(*) 网盟任务 from hy_Info where hy_info_menuid in(24,25,26,27,33,34,35,36,37,38,39,40,41) group by sys_auserid)b on a.rn =b.rn
inner join
(select row_number() over(order by hy_info_menuid) rn,count(*) 流程任务 from hy_Info where hy_info_menuid in(43,45,47,48,49,50,51,52,54,55,56,57,92,96,123) group by sys_auserid)c on a.rn =c.rn
dawugui 2012-03-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dawugui 的回复:]
SQL code
select sys_auserid,
sum(case when hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) then 1 else 0 end) [搜索任务],
sum(case when hy_info_menuid in(24,25,26,27,33……
[/Quote]貌似你的语句有的问题,也影响到我了.
更改为如下:
select sum(case when hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) then 1 else 0 end) [搜索任务],
sum(case when hy_info_menuid in(24,25,26,27,33,34,35,36,37,38,39,40,41) then 1 else 0 end) [网盟任务],
sum(case when hy_info_menuid in(43,45,47,48,49,50,51,52,54,55,56,57,92,96,123) then 1 else 0 end) [流程任务]
from hy_Info
dawugui 2012-03-14
  • 打赏
  • 举报
回复
select sys_auserid,
sum(case when hy_info_menuid in(7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23) then 1 else 0 end) [搜索任务],
sum(case when hy_info_menuid in(24,25,26,27,33,34,35,36,37,38,39,40,41) then 1 else 0 end) [网盟任务],
sum(case when hy_info_menuid in(43,45,47,48,49,50,51,52,54,55,56,57,92,96,123) then 1 else 0 end) [流程任务]
from hy_Info group by sys_auserid
nitaiyoucala 2012-03-14
  • 打赏
  • 举报
回复
有人么,

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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