|
@@ -1562,234 +1562,79 @@
|
|
|
</select>
|
|
|
|
|
|
<select id="aggregateAll" resultType="map">
|
|
|
- <!-- 1. today -->
|
|
|
- SELECT 'today' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'today' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime = #{today}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime = #{today}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND freezingTime = #{today}
|
|
|
UNION ALL
|
|
|
- <!-- 2. yesterday -->
|
|
|
- SELECT 'yesterday' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime = #{yesterday}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'month' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime = #{yesterday}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND freezingTime BETWEEN #{monthStart}
|
|
|
+ AND #{monthEnd}
|
|
|
UNION ALL
|
|
|
- <!-- 3. month -->
|
|
|
- SELECT 'month' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime BETWEEN #{monthStart} AND #{monthEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'year' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime BETWEEN #{monthStart} AND #{monthEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND freezingTime BETWEEN #{yearStart}
|
|
|
+ AND #{yearEnd}
|
|
|
UNION ALL
|
|
|
- <!-- 4. last_month -->
|
|
|
- SELECT 'last_month' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime BETWEEN #{lastMonthStart} AND #{lastMonthEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'yesterday' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime BETWEEN #{lastMonthStart} AND #{lastMonthEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND freezingTime = #{yesterday}
|
|
|
UNION ALL
|
|
|
- <!-- 5. year -->
|
|
|
- SELECT 'year' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'last_month' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime BETWEEN #{yearStart} AND #{yearEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime BETWEEN #{yearStart} AND #{yearEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND freezingTime BETWEEN #{lastMonthStart}
|
|
|
+ AND #{lastMonthEnd}
|
|
|
UNION ALL
|
|
|
- <!-- 6. last_year -->
|
|
|
- SELECT 'last_year' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime BETWEEN #{lastYearStart} AND #{lastYearEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'last_year' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND freezingTime BETWEEN #{lastYearStart} AND #{lastYearEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND freezingTime BETWEEN #{lastYearStart}
|
|
|
+ AND #{lastYearEnd}
|
|
|
UNION ALL
|
|
|
- <!-- 7. same_day (按 dataTime 区间) -->
|
|
|
- SELECT 'same_day' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{sameDayStart} AND #{sameDayEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'same_day' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{sameDayStart} AND #{sameDayEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND dataTime BETWEEN #{sameDayStart}
|
|
|
+ AND #{sameDayEnd}
|
|
|
UNION ALL
|
|
|
- <!-- 8. same_month -->
|
|
|
- SELECT 'same_month' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{sameMonthStart} AND #{sameMonthEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'same_month' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{sameMonthStart} AND #{sameMonthEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND dataTime BETWEEN #{sameMonthStart}
|
|
|
+ AND #{sameMonthEnd}
|
|
|
UNION ALL
|
|
|
- <!-- 9. same_year -->
|
|
|
- SELECT 'same_year' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'same_year' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{sameYearStart} AND #{sameYearEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{sameYearStart} AND #{sameYearEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND dataTime BETWEEN #{sameYearStart}
|
|
|
+ AND #{sameYearEnd}
|
|
|
UNION ALL
|
|
|
- <!-- 10. last_year_same_day -->
|
|
|
- SELECT 'last_year_same_day' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{lastYearSameDayStart} AND #{lastYearSameDayEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'last_year_same_day' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{lastYearSameDayStart} AND #{lastYearSameDayEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
-
|
|
|
+ AND dataTime BETWEEN #{lastYearSameDayStart}
|
|
|
+ AND #{lastYearSameDayEnd}
|
|
|
UNION ALL
|
|
|
- <!-- 11. last_year_same_month -->
|
|
|
- SELECT 'last_year_same_month' AS type,
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
- FROM ht_analog_data
|
|
|
- WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{lastYearSameMonthStart} AND #{lastYearSameMonthEnd}
|
|
|
- ORDER BY dataTime DESC
|
|
|
- LIMIT 1)
|
|
|
- ,0)
|
|
|
- -
|
|
|
- IFNULL(
|
|
|
- (SELECT epp
|
|
|
+ SELECT 'last_year_same_month' as type,
|
|
|
+ COALESCE(MAX(epp) - MIN(epp), 0) as value
|
|
|
FROM ht_analog_data
|
|
|
WHERE deviceName = #{deviceCode}
|
|
|
- AND dataTime BETWEEN #{lastYearSameMonthStart} AND #{lastYearSameMonthEnd}
|
|
|
- ORDER BY dataTime ASC
|
|
|
- LIMIT 1)
|
|
|
- ,0) AS value
|
|
|
+ AND dataTime BETWEEN #{lastYearSameMonthStart}
|
|
|
+ AND #{lastYearSameMonthEnd}
|
|
|
</select>
|
|
|
</mapper>
|