就需要用到union和union all关键字来实现这样的功能,union和union all的主要区别是union all是把结果集直接合并在一起,而
union 是将union all后的结果进行一次distinct,去除重复的记录后的结果。
最笨的方式就是把这么多条查询结果当成表,然后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 U.My_User_ID,U.My_User_Name,count(A.My_Article_UserID) as User_Count From My_User as U left join My_Artcile as A on U.My_User_ID = A.My_Article_UserID-- 查询两张表,分别取别名 U 和 A。左联A表查询。on是两张表的条件(两个id对应)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)