mysql查询语句 多条合并
selectcount(t1.fXM)asA1fromKJ_KJHDRYMXBt1wheret1.fDW='a部'selectcount(t2.fJSZW)ASA2fro...
select count(t1.fXM)as A1 from KJ_KJHDRYMXB t1 where t1.fDW = 'a部'
select count(t2.fJSZW)AS A2 from KJ_KJHDRYMXB t2 where t2.fJSZW = '项目人员' and t2.fDW = 'a部'
select count(t3.fJSZW)AS A3 from KJ_KJHDRYMXB t3 where (t3.fJSZW = '服务人员'or t3.fJSZW = '管理人员') and t3.fDW = 'a部'
select count(t31.fXB)AS A4 from KJ_KJHDRYMXB t31 where t31.fXB = '女' and t31.fDW = 'a部'
select count(t4.fZC)AS A5 from KJ_KJHDRYMXB t4 where (t4.fZC = '高级职称'or t4.fZC = '中级职称')and t4.fDW = 'a部'
select count(t5.fXM)AS A6 from KJ_KJHDRYMXB t5 where t5.fDW = 'a部'
select count(t6.fXL)AS A7 from KJ_KJHDRYMXB t6 where t6.fXL = '博士'and t6.fDW = 'a部'
select count(t7.fXL)AS A8 from KJ_KJHDRYMXB t7 where t7.fXL = '硕士' and t7.fDW = 'a部'
select count(t8.fXL)AS A9 from KJ_KJHDRYMXB t8 where t8.fXL = '本科'and t8.fDW = 'a部' 展开
select count(t2.fJSZW)AS A2 from KJ_KJHDRYMXB t2 where t2.fJSZW = '项目人员' and t2.fDW = 'a部'
select count(t3.fJSZW)AS A3 from KJ_KJHDRYMXB t3 where (t3.fJSZW = '服务人员'or t3.fJSZW = '管理人员') and t3.fDW = 'a部'
select count(t31.fXB)AS A4 from KJ_KJHDRYMXB t31 where t31.fXB = '女' and t31.fDW = 'a部'
select count(t4.fZC)AS A5 from KJ_KJHDRYMXB t4 where (t4.fZC = '高级职称'or t4.fZC = '中级职称')and t4.fDW = 'a部'
select count(t5.fXM)AS A6 from KJ_KJHDRYMXB t5 where t5.fDW = 'a部'
select count(t6.fXL)AS A7 from KJ_KJHDRYMXB t6 where t6.fXL = '博士'and t6.fDW = 'a部'
select count(t7.fXL)AS A8 from KJ_KJHDRYMXB t7 where t7.fXL = '硕士' and t7.fDW = 'a部'
select count(t8.fXL)AS A9 from KJ_KJHDRYMXB t8 where t8.fXL = '本科'and t8.fDW = 'a部' 展开
展开全部
最笨的方式就是把这么多条查询结果当成表,然后select全部,虽然笛卡尔积,但是每个查询都只有一条记录。
select * from
(select count(t1.fXM)as A1 from KJ_KJHDRYMXB t1 where t1.fDW = 'a部' )a,
(select count(t2.fJSZW)AS A2 from KJ_KJHDRYMXB t2 where t2.fJSZW = '项目人员' and t2.fDW = 'a部')b,
(select count(t3.fJSZW)AS A3 from KJ_KJHDRYMXB t3 where (t3.fJSZW = '服务人员'or t3.fJSZW = '管理人员') and t3.fDW = 'a部')c,
(select count(t31.fXB)AS A4 from KJ_KJHDRYMXB t31 where t31.fXB = '女' and t31.fDW = 'a部')d
(select count(t4.fZC)AS A5 from KJ_KJHDRYMXB t4 where (t4.fZC = '高级职称'or t4.fZC = '中级职称')and t4.fDW = 'a部')d,
(select count(t5.fXM)AS A6 from KJ_KJHDRYMXB t5 where t5.fDW = 'a部')e
(select count(t6.fXL)AS A7 from KJ_KJHDRYMXB t6 where t6.fXL = '博士'and t6.fDW = 'a部')f
(select count(t7.fXL)AS A8 from KJ_KJHDRYMXB t7 where t7.fXL = '硕士' and t7.fDW = 'a部')g
(select count(t8.fXL)AS A9 from KJ_KJHDRYMXB t8 where t8.fXL = '本科'and t8.fDW = 'a部')h
更多追问追答
追问
这是就一个表,能不能简化一下。
追答
select count(t1.fXM)as A1,
count(case when t1.fJSZW = '项目人员' then t1.fJSZW else null end)A2,
count(case when t1.fJSZW = '服务人员' or t1.fJSZW = '管理人员' then t1.fJSZW else null end)A3,
.......
from KJ_KJHDRYMXB t1 where t1.fDW = 'a部'
以这种方式,但是不知道mysql支不支持
展开全部
这样应该可以,你可以试一下。
select count(if(t1.fDW = 'a部',1,0))as A1 ,count(if(t2.fJSZW = '项目人员' and t2.fDW = 'a部',1,0))AS A2,count(if((t3.fJSZW = '服务人员'or t3.fJSZW = '管理人员') and t3.fDW = 'a部',1,0))AS A3
from KJ_KJHDRYMXB
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
union union all
更多追问追答
追问
如果多表,也这么合并么,
追答
select count(t1.fXM)as A1 from KJ_KJHDRYMXB t1 where t1.fDW = 'a部' union select count(t2.fJSZW)AS A2 from KJ_KJHDRYMXB t2 where t2.fJSZW = '项目人员' and t2.fDW = 'a部'
这样就行了union不允许重复的值 union all 允许重复值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询