From b284d078f196af80a105dc3bcb610d8ed37d9251 Mon Sep 17 00:00:00 2001 From: ZhuDongming <773644075@qq.com> Date: Fri, 08 Nov 2019 11:49:29 +0800 Subject: [PATCH] update --- src/main/resources/mapper/HistoryHourlyMapper.xml | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) diff --git a/src/main/resources/mapper/HistoryHourlyMapper.xml b/src/main/resources/mapper/HistoryHourlyMapper.xml index 599bac1..8f5404c 100644 --- a/src/main/resources/mapper/HistoryHourlyMapper.xml +++ b/src/main/resources/mapper/HistoryHourlyMapper.xml @@ -17,4 +17,43 @@ </if> </where> </select> + + <select id="getPollutionSourceDataByHour" resultType="java.util.Map"> + SELECT + DATE_FORMAT(time,'%Y-%m-%d %H') time, + <foreach collection="sensorKeys" separator="," item="sensorKey"> + AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}' + </foreach> + FROM + history h + <where> + <if test="mac!=null"> + and h.mac=#{mac} + </if> + </where> + GROUP BY + DATE_FORMAT(time,'%Y-%m-%d %H') + <if test="time!=null"> + having time=DATE_FORMAT(DATE_SUB(#{time}, INTERVAL 1 HOUR),'%Y-%m-%d %H') + </if> + </select> + + <select id="getPollutionSourceDataAll" resultType="java.util.Map"> + SELECT + DATE_FORMAT(time,'%Y-%m-%d %H') time, + <foreach collection="sensorKeys" separator="," item="sensorKey"> + AVG(h.value ->'$.${sensorKey}') AS '${sensorKey}' + </foreach> + FROM + history h + <where> + <if test="mac!=null"> + and h.mac=#{mac} + </if> + </where> + GROUP BY + DATE_FORMAT(time,'%Y-%m-%d %H') + order by time desc + limit 0,1 + </select> </mapper> \ No newline at end of file -- Gitblit v1.8.0