浏览代码

修改sql最新值分组

yuejiaying 4 年之前
父节点
当前提交
245c06bff3
共有 1 个文件被更改,包括 3 次插入3 次删除
  1. 3 3
      sms_water/src/main/resources/mapper/OnlineMonitorMapper.xml

+ 3 - 3
sms_water/src/main/resources/mapper/OnlineMonitorMapper.xml

@@ -239,7 +239,7 @@
         )t5 on t5.device_id=t4.id
         left join sms_alarm_details t6 on t6.device_id=t4.id and t6. status = 1 and t6.attribute_id = t5.attribute_id and t6.state = 1
         left join (
-            select parent_scene_id,max(latest_value) latest_value
+            select b1.device_id,b1.attribute_id,max(latest_value) latest_value
             from sms_day_report b1
             where b1.year = year(now() + interval-1 day) and b1.year = month(now() + interval-1 day) and b1.day = day(now() + interval-1 day)
                 <if test="sceneIds != null and sceneIds.size() > 0">
@@ -248,8 +248,8 @@
                         #{item}
                     </foreach>
                 </if>
-            group by  parent_scene_id
-        )t8 on t8.parent_scene_id = t1.id
+            group by  b1.device_id,b1.attribute_id
+        )t8 on t8.attribute_id =t5.attribute_id and t8.device_id=t5.device_id
         where t1.parent_scene_id = 0 and t1. status = 1
         <if test="sceneTypeName != null and sceneTypeName != '' ">
             and t3.scene_type_name = #{sceneTypeName}