mysql一些语句
Posted 吴大哥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql一些语句相关的知识,希望对你有一定的参考价值。
<!-- 报警量排行按创建时间每月来排行 -->
<select id="alarmDaySort" resultType="alarm">
select DATE_FORMAT(create_date,‘%Y-%m‘) as jlTime,
count(*) as jlAll
from amp_alarm_log a group by jlTime ORDER BY jlTime DESC LIMIT 12
</select>
<!-- 地区企业排行 不同地区的企业数目 -->
<select id="areaSort" resultType="alarm">
SELECT b.`name` as areaName,
COUNT(c.area_code) as companySum
FROM sys_area b
LEFT JOIN amp_ent_info c on b.`CODE` =c.area_code
GROUP BY b.`code` HAVING b.`code` LIKE ‘3307__‘
</select>
<!-- 报警等级近30天的数据排行 -->
<select id="alarmLevel" resultType="alarm">
SELECT
truncate(t2.levelHigh/t1.levelAll*100,2) as levelHighPercent,
truncate(t3.levelMid/t1.levelAll*100,2) as levelMidPercent,
truncate(t4.levelLow/t1.levelAll*100,2) as levelLowPercent
from
(SELECT count(*) as levelAll from amp_alarm_log where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= create_date) t1,
(SELECT count(*) as levelHigh from amp_alarm_log a where a.level=3 and DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= create_date) t2,
(SELECT count(*) as levelMid from amp_alarm_log a where a.level=2 and DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= create_date) t3,
(SELECT count(*) as levelLow from amp_alarm_log a where a.level=1 and DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= create_date) t4
</select>
以上是关于mysql一些语句的主要内容,如果未能解决你的问题,请参考以下文章