码迷,mamicode.com
首页 > 数据库 > 详细

mysql一些语句

时间:2017-09-15 10:06:12      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:info   --   level   orm   val   sql   sys   form   left join   

<!-- 报警量排行按创建时间每月来排行 -->
<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) &lt;= create_date) t1,
(SELECT count(*) as levelHigh from amp_alarm_log a where a.level=3 and DATE_SUB(CURDATE(), INTERVAL 30 DAY) &lt;= create_date) t2,
(SELECT count(*) as levelMid from amp_alarm_log a where a.level=2 and DATE_SUB(CURDATE(), INTERVAL 30 DAY) &lt;= create_date) t3,
(SELECT count(*) as levelLow from amp_alarm_log a where a.level=1 and DATE_SUB(CURDATE(), INTERVAL 30 DAY) &lt;= create_date) t4
</select>

mysql一些语句

标签:info   --   level   orm   val   sql   sys   form   left join   

原文地址:http://www.cnblogs.com/wudage/p/7524398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!