|
最初由 magicangel 发布
[B]select b.id,a.a,a.b
from (select top 100000000 a.a,a.b,count(1) seq from #magic a,#magic b where a.a=b.a and a.b>=b.b group by a.a,a.b order by a.a,a.b desc) a,
(select top 100000000 a.id,a.a,count(1) seq from #magic a,#magic b where a.a=b.a and a.id>=b.id group by a.a,a.id order by a.a,a.id desc) b
where a.a=b.a and a.seq=b.seq
--------------------------------------------
思路是这样的:
1字段a不变产生两个表,两个表里的id和b分别降序
2引入count(1)再结合a字段进行平行连接 [/B]
你的思路是对的,不过我比较菜.你的语句按照我的实际情况改完测试了不能通过
是不是我哪里改错了?
select * into #magic from bbs
select b.announceid,a.rootid,a.dateandtime
from (select top 100000000 a.announceid,a.dateandtime,count(1) seq from #magic a,#magic b
where a.rootid=b.rootid and a.dateandtime>=b.dateandtime group by a.rootid,a.dateandtime order by a.rootid,a.dateandtime desc) a,
(select top 100000000 a.announceid,a.rootid,count(1) seq from #magic a,#magic b where a.rootid=b.rootid and a.announceid>=b.announceid group by a.rootid,a.announceid order by a.rootid,a.announceid desc) b
where a.rootid=b.rootid and a.seq=b.seq |
|