我在数据库中用有表
stugradegradeid xuehao grade updatetime comment
1 2003611 89 2006-9-13
2 2003611 90 2006-9-9
3 2003615 92 2006-8-25
4 2003615 85 2006-8-30现在我想要每个学生(xuehao)的最后修改的记录(也就是删除以前的记录)
这个该怎么做到啊谢谢
stugradegradeid xuehao grade updatetime comment
1 2003611 89 2006-9-13
2 2003611 90 2006-9-9
3 2003615 92 2006-8-25
4 2003615 85 2006-8-30现在我想要每个学生(xuehao)的最后修改的记录(也就是删除以前的记录)
这个该怎么做到啊谢谢
解决方案 »
- 如何比较时间呢?我想判断 7:30之前是前一天的夜班,但是7:30后,就是今天白班
- 关于排序的问题,高手来看一下吧,谢谢了
- 数据源连接不上用户,求救!
- 大侠们,问个查询语句!
- 在调试一个触发器实例时遇到的问题(附源码)
- 作业执行包错误:用户'sa'登陆失败。请教高手指点
- SQL变态笔试题(续。。。)求解。。。高手来!~~
- 请问各路英雄一个动态sql的问题
- SQL Server 2000有没有这个功能,散分!!
- SQL SERVER中的一个触发器,新增可以触发,可删除却不可以,该怎么写?
- 如何用sp_attach_db存储过程把数据库加载到其它的服务器上
- 关于游标,我想把符合条件的记录的某一个字段的值,全部组成一个字符串,请问如何实现?
from stugrade a
where not exists(
select * from stugrade where xuehao=a.xuehao and updatetime>a.updatetime)
--如果某个学号只有一条记录,要保留
delete a
from stugrade a
where exists(
select * from stugrade where xuehao=a.xuehao and updatetime>a.updatetime)
insert into @t
select 1,2003611,89,'2006-9-13'
union all
select 2,2003611,90,'2006-9-9'
union all
select 3,2003615,92,'2006-8-25'
union all
select 4,2003615,85,'2006-8-30'
union all
select 5,2003616,85,'2007-01-01'delete a from @t a
where updatetime<>(select max(updatetime) from @t where xuehao=a.xuehao)
select * from @t
结果:
1 2003611 89 2006-09-13 00:00:00.000
4 2003615 85 2006-08-30 00:00:00.000
5 2003616 85 2007-01-01 00:00:00.000
go
select id,name from #t where id1 in(select max(id1) from #t group by id)