1、orderby 时间1 desc
2、delete from 表 where 时间2<getdate()
2、delete from 表 where 时间2<getdate()
解决方案 »
- 插入记录时不知道主键(numeric)的值,如何设置主键自增?
- 自增长字段的数据类型用 int 还是 bigint 好,数据日增长量平均在 500 条以内。
- 怪事!我的SQL Server怎么ping不到,但是能连到!
- 发现一个奇怪问题?
- 把选择的条目复制到临时表或表变量中,如何做?
- 如何提出合成字段中某项为空的记录,谢谢
- 请问有没有比较好的SQL2000帮助文件,好久没用了都忘了语法了
- sql server时删除记录后再插入数据没有插入到最后
- 请教一个sql查询语句
- 用insert语句插入数据,在内容中有引号怎么办
- 在分页方面SQL SERVER 和oracal差好多啊
- 请问谁能够帮我优化以下数据库的查询速度!!急!!!!!!!!!
问题一:
我的意思是
order by 时间1-当前时间 =最小值 asc正确的该怎么写????问题二这句话应该写在哪?我如果应用它哪?
selct min(datediff(d,时间1,getdate())),时间1 from table
2、
delete from table where 时间2=
(select A.时间1 from (selct min(datediff(d,时间1,getdate())),时间1 from table ) A)
selct min(datediff(d,时间1,getdate())),时间1 from table group by 时间1
2、
delete from table where 时间2=
(select A.时间1 from (selct min(datediff(d,时间1,getdate())),时间1 from table group by 时间1) A)
-----------------------------------------
意思实际就是最靠近当前时间的时间吧,也就是最大的时间啦。那就直接
Order By 时间1 Desc
就可以啊。