把俩条MySQL语句合并成一条
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了把俩条MySQL语句合并成一条相关的知识,希望对你有一定的参考价值。
select date_format(a.atime,'%H') as alarmhour,count(*) as twicecount from z_alarm a where a.s_est=1 and a.ifdel=0 and a.atime like '2019-02-18%' group
by date_format(a.atime,'%H') ;
select date_format(a.atime,'%H') as alarmhour,count(*) as twicecount from z_alarm_false a where a.atime like '2019-02-18%' group by date_format(a.atime,'%H') ;
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 参考技术B
两张表有关联关系吗,两张表没有关系的话用union all 或者 UNION 将两个查询结果拼成一个结果集,在查询那个结果集;(union all 和 union 请参考连接:http://www.w3school.com.cn/sql/sql_union.asp)
eg:
select alarmhour,twicecount from (select date_format(a.atime,'%H') as alarmhour,
count(*) as twicecount
from z_alarm a
where a.s_est=1 and a.ifdel=0 and a.atime like '2019-02-18%'
group by date_format(a.atime,'%H')
union all
select date_format(b.atime,'%H') as alarmhour,
count(*) as twicecount
from z_alarm_false b where b.atime like '2019-02-18%'
group by date_format(b.atime,'%H')
) aa追问
有关联,我要比较俩条sql语句统计的数据条件以相同时间进行比较
mysql中将多行数据合并成一行数据
.1GROUP_CONCAT()中的值为你要合并的数据的字段名;
SEPARATOR 函数是用来分隔这些要合并的数据的;
\' \'中是你要用哪个符号来分隔;
2.必须要用GROUP BY 语句来进行分组管理,不然所有的数据都会被合并成一条记录
SELECT am.activeId,GROUP_CONCAT(m.modelName SEPARATOR \',\') modelName FROM activemodel am JOIN model m ON am.modelId=m.modelId
WHERE m.valid=1 GROUP BY am.activeId
原文https://www.cnblogs.com/guaiguaipaizz/p/6501676.html
以上是关于把俩条MySQL语句合并成一条的主要内容,如果未能解决你的问题,请参考以下文章