如何在Sql中使用其他列删除记录 [英] How Do I Delete Records By Using Other Column In Sql

查看:64
本文介绍了如何在Sql中使用其他列删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ID	DATE
1	2015-07-23 04:00:02.000
2	2015-07-24 04:00:02.000
3	2015-07-25 04:00:02.000
4	2015-07-26 04:00:02.000
5	2015-07-27 04:00:02.000
6	2015-07-28 04:00:02.000
7	2015-07-29 04:00:02.000
8	2015-07-30 04:00:02.000







如何使用id列删除前2个日期记录请解释我存储过程代码,因为每次我不能在条件




how do i delete the top 2 date record by using id column please explain me on stored procedure code because i have lot lakhs of records every time i cannot mention date in where condition

推荐答案

中提及日期我有很多十万条记录我已将上述给定数据放入ans表中



从sdate desc中选择前2 *进#temp来自ans订单



select * from #temp



从ans中删除其中的id(从#temp中选择id)



select * from ans



drop table #temp
I have place the above given data into ans table

select top 2 * into #temp from ans order by sdate desc

select * from #temp

delete from ans where id in (select id from #temp)

select * from ans

drop table #temp


DELETE from mytable WHERE id IN (SELECT TOP 2 ID FROM mytable ORDER BY Date ASC)


这篇关于如何在Sql中使用其他列删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆