id        title             time                      childid   
40102552 巾帼枭雄ⅱ10 2011-10-25 23:11:00.000 72795
40102549 下海8 2011-10-25 21:00:00.000 77341
40102548 前情提要《下海》8 2011-10-25 20:56:00.000 77341
40102547 下海7 2011-10-25 20:05:00.000 77341
40102546 前情提要《下海》7 2011-10-25 20:00:00.000 77341
40102540 谁知女人心3 2011-10-25 15:50:00.000 73758
40102539 谁知女人心2 2011-10-25 14:56:00.000 73758
40102538 谁知女人心1 2011-10-25 14:03:00.000 73758

40102537 无忧花开27 2011-10-25 13:10:00.000 76109
要求查询结果,childid 不重复,根据time降序查询 

解决方案 »

  1.   

    select distinct * from tb order by time desc
      

  2.   

    select * from tb t where time=(select max(time) from tb where childid=t.childid) order by time desc 
      

  3.   

    select top 10 * from tb a
    where not exists(select 1 from tb where childid=a.childid and time>a.time)
    order by time
      

  4.   

    select top 10 * from tb t where time=(select max(time) from tb where childid=t.childid) order by time desc
      

  5.   

    朋友首页谢谢你的有时间来帮忙我解答问题。
       其次,你的sql,我测试了,结果 不是我想要的哦。
      

  6.   

    create table tb(id int,title nvarchar(20),time datetime,childid int)
    insert into tb select 40102552,'巾帼枭雄ⅱ10 ','2011-10-25 23:11:00.000', 72795
    insert into tb select 40102549,'下海8 ','2011-10-25 21:00:00.000', 77341
    insert into tb select 40102548,'前情提要《下海》8 ','2011-10-25 20:56:00.000', 77341
    insert into tb select 40102547,'下海7 ','2011-10-25 20:05:00.000', 77341
    insert into tb select 40102546,'前情提要《下海》7 ','2011-10-25 20:00:00.000', 77341
    insert into tb select 40102540,'谁知女人心3 ','2011-10-25 15:50:00.000', 73758
    insert into tb select 40102539,'谁知女人心2 ','2011-10-25 14:56:00.000', 73758
    insert into tb select 40102538,'谁知女人心1 ','2011-10-25 14:03:00.000', 73758
    insert into tb select 40102537,'无忧花开27 ','2011-10-25 13:10:00.000', 76109
    go
    select top 10 * from tb a
    where not exists(select 1 from tb where childid=a.childid and time>a.time)
    order by time
    /*
    id          title                time                    childid
    ----------- -------------------- ----------------------- -----------
    40102537    无忧花开27               2011-10-25 13:10:00.000 76109
    40102540    谁知女人心3               2011-10-25 15:50:00.000 73758
    40102549    下海8                  2011-10-25 21:00:00.000 77341
    40102552    巾帼枭雄ⅱ10              2011-10-25 23:11:00.000 72795(4 行受影响)
    */
    go
    drop table tb
      

  7.   

    Select id title time childid from 表名 tb1 where not exists(select 1 from 表名 where 表名.childid =a.childid and ID<a.ID) order by 字段 desc
    这个应该能实现。