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降序查询
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降序查询
解决方案 »
- 如何在一个触发器里写多条insert语句
- sql2000 连接超时时间的设定
- 我在SQLSERVER2000基础上安装的SQLSERVER2005,在visual studio.net下不能进行单步调试,而在一个没有装过SQLSERVER的机器上安装的SERVER2005就可以
- 初学SQL...这样的简单的SQL...蛮有意思....
- sql并发读写疑问
- ☆☆ 求一SQL语句 ☆☆
- 帮忙看看sql语局
- 删除远程表报错
- 如何做到SQL Server2000的全部备份和新增备份?如何还原?(在BCB中用程序实现)
- SQL Server有病
- SQL Server Compact 3.5问题
- 救命 SQL2005再遇诡异问题
where not exists(select 1 from tb where childid=a.childid and time>a.time)
order by time
其次,你的sql,我测试了,结果 不是我想要的哦。
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
这个应该能实现。