日期:2014-05-18  浏览次数:20416 次

SQL分组查询,急!
select rank () over (order by testtime desc) xh,Stationinfo.StationState,Stationinfo.StationName,Report.Dpress,History.* from History left join Stationinfo on History.StationName=Stationinfo.Agreement left join Report on Report.StationName=History.StationName
where Testtime< convert(varchar(10),getdate(),120) and History.ID in(select max(ID) from History) and Report.ID in(select max(ID) FROM Report)
order by Testtime desc

紫仲 0.00 459 NULL NULL NULL NULL NULL 2011-12-10 18:52:13.000 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 0.00 699.70 0.00 0.30 0.01 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 NULL NULL 0.00 700.01 0.00 0.00 0.00 0.00 0.00 NULL NULL NULL NULL NULL NULL NULL 13911111111 NULL NULL NULL NULL NULL 0.00 NULL 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0 0 0 0 0 0.00 0.00 0.00 0
这是查询出来的结果,只能查出紫仲这一个店的数据,我想查出History这个表中所有店的最新数据。也就是只查询出每个店最后一次上传的数据。一个店只显示一条。我写的SQL如何修改?

------解决方案--------------------
select max(ID) from History

==>

select max(ID) from History group by 店