如何将下列三个语句连城一个语句组成一个数据集

select count(*) from  `crm_module_1` where field14='流程'   
select count(*) from  `crm_module_1` where field14='技术'    
select count(*) from  `crm_module_1`
这三个语句怎么连起来 写成一个数据集啊

FineReport guduran 发布于 2020-5-25 14:00
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共2回答
最佳回答
0
zsh331Lv8专家互助
发布于2020-5-25 14:03


select count(*) as gs from  `crm_module_1` where field14='流程'   

union all

select count(*) as gs from  `crm_module_1` where field14='技术'    

union all

select count(*) as gs from  `crm_module_1`


最佳回答
1
happy_cangcangLv4初级互助
发布于2020-5-25 14:33

MySql的写法:

select count(case when field14='流程' then 1 else null end) as '流程',
       count(case when field14='技术' then 1 else null end) as '技术',
       count(1) as '总数'
from crm_module_1;


还可以用sum

select sum(case when field14='流程' then 1 else 0 end) as '流程',
       sum(case when field14='技术' then 1 else 0 end) as '技术',
       sum(1) as '总数'
from crm_module_1;


  • guduran guduran(提问者) 你这种写法适合SQL 语句吗? 我写到其他地方提示 SQL解析失败
    2020-05-25 15:51 
  • happy_cangcang happy_cangcang 回复 guduran(提问者) 我这就是sql语句呀,不同的数据库会有细微的差异,得看你用的是什么数据库
    2020-05-25 15:56 
  • guduran guduran(提问者) 回复 happy_cangcang mysql 的数据库
    2020-05-25 16:05 
  • happy_cangcang happy_cangcang 回复 guduran(提问者) 在我这是可以运行的,你那报什么错?是不是我字段名,表名什么的写错了?
    2020-05-25 16:11 
  • 3关注人数
  • 458浏览人数
  • 最后回答于:2020-5-25 14:33
    请选择关闭问题的原因
    确定 取消
    返回顶部