--try
select T.Cid,
       T.Cdate
from
(
select a.Cid as Cid,b.Cdate as Cdate,... from 表 a,表 b
) T
Group By T.CID
Having count(T.CID)=2
order by T.Cdate desc

解决方案 »

  1.   

    select
        c.*
    from
        结果集 c
    where
        c.Cdate in(select top 2 Cdate from 结果集 where Cid=c.Cid order by Cdate desc)
      

  2.   

    select
        a.*
    from
        table a
    where
        a.Cdate in(select top 2 Cdate from table where Cid=a.Cid order by Cdate desc)
      

  3.   

    --Sorry,有点错误,这样好一点
    select T.Cid,
           T.Cdate
    from
    (
    select a.Cid as Cid,b.Cdate as Cdate,... from 表 a,表 b
    ) T
    where 
    T.Cdate  in(select top 2 T1.Cdate from 
    (
    select a.Cid as Cid,b.Cdate as Cdate,... from 表 a,表 b
    ) T1
    where T1.Cid=T.Cid order by T1.Cdate desc)
      

  4.   

    假设结果集为C
    select
        C1.*
    from  C C1
    where EXISTS (select  1 FROM (SELECT * top 2 Cdate from C C2 where C2.Cid=C1.Cid order by Cdate desc)D WEHRE D.Cdate = C1.Cdate)
      

  5.   

    libin_ftsafe(子陌红尘) ,lizhaogui() 和 zlp321002(一生一世,平平安按) 的第二个答案,都是对的.
    谢谢大家帮助!结贴!
      

  6.   

    --测试数据
    create table #(Cid int,Cdate datetime)insert into # 
    select  1,'2005-10-1'
    union all select 2,'2005-10-2'
    union all select 1,'2005-10-3'
    union all select 3,'2005-10-4'
    union all select 1,'2005-10-5'
    union all select 2,'2005-10-6'
    union all select 2,'2005-10-7'select * from #--产生结果集
    select
        c.*
    from
        # c
    where
        c.Cdate in(select top 2 Cdate from # where Cid=c.Cid order by Cdate desc)
    order by cid,cdate desc