sql优化

This commit is contained in:
2025-06-30 13:11:05 +08:00
parent 49a3ce2c11
commit cebd845af1
13 changed files with 356 additions and 169 deletions

View File

@ -115,7 +115,7 @@
</delete>
<select id="getAmmeterDetailInfo" parameterType="String" resultType="com.xzzn.ems.domain.vo.AmmeterDataDetailInfo">
select t.category as category,
SELECT t.category as category,
t.total_kwh as totalKwh,
t.sharp_kwh as sharpKwh,
t.flat_kwh as flatKwh,
@ -123,10 +123,15 @@
t.valley_kwh as valleyKwh,
t.device_id as deviceId,
Max(t.data_update_time) as updateTime
from ems_ammeter_data t
where t.site_id = #{siteId}
and t.data_update_time = (select MAX(tmp.data_update_time) from ems_ammeter_data tmp where tmp.site_id = t.site_id and tmp.device_id = t.device_id)
group by t.category,t.total_kwh,t.flat_kwh,t.peak_kwh,t.valley_kwh,t.device_id
FROM ems_ammeter_data t
INNER JOIN (
SELECT p.site_id, p.device_id,p.category,MAX(p.data_update_time) AS max_update_time
FROM ems_ammeter_data p
WHERE p.site_id = #{siteId}
GROUP BY p.site_id,p.device_id,p.category
) latest on t.device_id = latest.device_id and t.data_update_time = latest.max_update_time
WHERE t.site_id = #{siteId}
group by t.category,t.total_kwh,t.sharp_kwh,t.flat_kwh,t.peak_kwh,t.valley_kwh,t.device_id
order by updateTime desc
</select>
</mapper>