create table tb
(
id int
,date datetime
,dvalue int
)
insert into tb
select 1,'2011-12-30 19:29:00',1
union all select 1,'2011-12-30 19:36:00',2
union all select 2,'2011-12-30 20:29:00',3
union all select 2,'2011-12-30 20:31:00',4
union all select 3,'2011-12-30 21:00:00',5
union all select 4,'2011-12-30 22:00:00',6
union all select 5,'2011-12-30 23:00:00',7-------显示结果-------
1,'2011-12-30 19:36:00',2
2,'2011-12-30 20:31:00',4
3,'2011-12-30 21:00:00',5
4,'2011-12-30 22:00:00',6
5,'2011-12-30 23:00:00',7
(
id int
,date datetime
,dvalue int
)
insert into tb
select 1,'2011-12-30 19:29:00',1
union all select 1,'2011-12-30 19:36:00',2
union all select 2,'2011-12-30 20:29:00',3
union all select 2,'2011-12-30 20:31:00',4
union all select 3,'2011-12-30 21:00:00',5
union all select 4,'2011-12-30 22:00:00',6
union all select 5,'2011-12-30 23:00:00',7-------显示结果-------
1,'2011-12-30 19:36:00',2
2,'2011-12-30 20:31:00',4
3,'2011-12-30 21:00:00',5
4,'2011-12-30 22:00:00',6
5,'2011-12-30 23:00:00',7
解决方案 »
- 将一个表分割成多个表对性能影响?
- 关于sql的with check option的问题
- windows xp 启动sql server 2005 时弹出的“连接到服务器”怎么设置啊?
- help
- 如果得知自己服务器上的数据库引擎(也就是SQL Server)被哪几台SQL Server的企业管理器所注册?
- welyngj 进来!
- selcct中有统计百分比的功能吗?
- 请教元素求并问题如何解决?
- SyBase与SQL server如何建立连接,以及从SQL里查询SyBase是的数据表
- 求触发器:在插入,更新一个数字列时,能更新另一个表中这个列的数字之和(在线等)
- SQL server2000的JOB执行出错
- 帮小弟写个简单的函数 谢谢
create table tb
(
id int
,date datetime
,dvalue int
)
insert into tb
select 1,'2011-12-30 19:29:00',1
union all select 1,'2011-12-30 19:36:00',2
union all select 2,'2011-12-30 20:29:00',3
union all select 2,'2011-12-30 20:31:00',4
union all select 3,'2011-12-30 21:00:00',5
union all select 4,'2011-12-30 22:00:00',6
union all select 5,'2011-12-30 23:00:00',7select * from tb as a where not exists(select 1 from tb where ID=a.ID and (date>a.date or(Date=a.Date and dvalue>a.dvalue)))/*
id date dvalue
1 2011-12-30 19:36:00.000 2
2 2011-12-30 20:31:00.000 4
3 2011-12-30 21:00:00.000 5
4 2011-12-30 22:00:00.000 6
5 2011-12-30 23:00:00.000 7
*/