Sql Server 根據條件查找多條數據中最大值的詳細記錄

--(正常效果)
select l.* from loadCurveSampling l
left join Meter m on l.meter_id=m.Meter_ID
 
--聚合當天最大值數據記錄 合併查詢(聚合效果)
select l.* from loadCurveSampling l,
(select meter_id,MAX(DT) DT from LoadCurveSampling where CONVERT(varchar(10), DT, 120)='2018-10-29' group by meter_id)b
left join Meter m on b.meter_id=m.Meter_ID
where l.meter_id=b.meter_id and l.DT=b.DT

效果以下:spa

相關文章
相關標籤/搜索