日期:2014-05-16  浏览次数:20598 次

求助,查询语句!
数据
设备类别   单位      统计日期                            数量
aa              单位1   2014-04-07-15-26              8
aa              单位1   2014-04-07-14-26              5
aa              单位1   2014-04-07-13-26              6
bb              单位2   2014-04-07-15-29             9
bb              单位2   2014-04-07-14-26              5
bb              单位2   2014-04-07-13-26              6
cc              单位2   2014-04-07-15-31             15   
cc              单位2   2014-04-07-14-26              5
cc              单位2   2014-04-07-13-26              6


想要是数据
aa              单位1   2014-04-07-15-26              8
bb              单位2   2014-04-07-15-29             9
cc              单位2   2014-04-07-15-31             15   

也就是想出每个设备类别和单位中最新统计的数据,感谢呀!!
------解决方案--------------------
select * from tb t where not exists(select 1 from tb where 设备类别 =t.设备类别  and 单位=t.单位 and  统计日期>t. 统计日期)

------解决方案--------------------
select * from table1 as a  where 
统计日期=(select max(统计日期) from table1 where 设备类别=a.设备类别)