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

效果如下:

posted @ 2019-08-16 10:22  渴死的鱼丶  阅读(4976)  评论(0编辑  收藏  举报