SQL语句按条件删除数据

[复制链接]
查看11 | 回复5 | 2012-2-10 11:05:02 | 显示全部楼层 |阅读模式
前提是secend中的username是主键 first中是username是外键语句如下delete from second where username in (select username from first where to_number(to_char(time,'yyyymmdd')) < 20120203) cascade;ps:否则还需要重新删除first中的行如下delete from first where to_number(to_char(time,'yyyymmdd')) < 20120203;...
回复

使用道具 举报

千问 | 2012-2-10 11:05:02 | 显示全部楼层
下面的两句可以实现你的要求的东东delete from second where username in(select username from first where CONVERT(int,SUBSTRING(time,0,9))<CONVERT(int,'20120203'))delete from first where CONVERT(i...
回复

使用道具 举报

千问 | 2012-2-10 11:05:02 | 显示全部楼层
delete from first where substr(time,1,8)<'20120203'delete from second where substr(time,1,8)<'20120203'...
回复

使用道具 举报

千问 | 2012-2-10 11:05:02 | 显示全部楼层
delete from second where username in (select username from first where left(time,8)<'20120303')delete from first where left(time,8)<'20120303'...
回复

使用道具 举报

千问 | 2012-2-10 11:05:02 | 显示全部楼层
DELETE FROM [secend]WHERE [username] IN(
SELECT [username] FROM [first]
WHERE SUBSTRING([time], 1, 8) < '20120203')DELETE FROM [first]WHERE SUBSTRING([time], 1, 8) < ...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行