日期:2014-05-18 浏览次数:20548 次
select top 5 b.id,b.cpmc,b.dateandtime,b.gsid,b.zsbz from spzs a inner join spzs b on a.id=b.id left join hot_top c on b.gsid=c.gsid where not exists(select 1 from spzs where flag=a.flag and gsid=a.gsid and flag=1 and dateandtime>a.dateandtime) order by case when c.gsid is not null then 0 when b.zsbz like '%02% ' then 1 else 2 end, b.dateandtime desc
------解决方案--------------------
复杂,真复杂,干吗搞那么复杂啊~~~~~~~~~~
------解决方案--------------------
楼主,最好把表写出来。看看。
具体点。谢谢。
------解决方案--------------------
select a.* from spzs a where dateandtime = (select max(dateandtime) from spzs where gsid = a.gsid) 至于top 5,你自己选择一个排序,如对gsid排序 select top 5 * from (select a.* from spzs a where dateandtime = (select max(dateandtime) from spzs where gsid = a.gsid)) t