请教,如何改写这个SQL

[复制链接]
查看11 | 回复6 | 2011-11-1 16:26:29 | 显示全部楼层 |阅读模式
delete from log partition(bt)
where rowid not in (select min(rowid) from log partition(bt) group by USERID,CREATETIME);
请教高人,如何将这个SQL的 NOT IN 改写为exist,谢谢!!
回复

使用道具 举报

千问 | 2011-11-1 16:26:29 | 显示全部楼层
delete from log a
where not exists (select null

from log b

where a.rowid=b.rowid

group by b.userid,b.createtime

having a.rowid=min(b.rowid)

)
但是这个不一定就快~没有最好的,只有最适合的。具体问题具体分析
回复

使用道具 举报

千问 | 2011-11-1 16:26:29 | 显示全部楼层
非常感谢!
回复

使用道具 举报

千问 | 2011-11-1 16:26:29 | 显示全部楼层
我试了,不行!
回复

使用道具 举报

千问 | 2011-11-1 16:26:29 | 显示全部楼层
09:50:19 SQL> delete from ddns_log a
09:53:37 2where not exists (select null
09:53:37 3
from ddns_log b
09:53:37 4
group by b.userid,b.createtime
09:53:37 5
having a.rowid=min(b.rowid)
09:53:37 6
);
回复

使用道具 举报

千问 | 2011-11-1 16:26:29 | 显示全部楼层
change to EXISTS:
delete from log partition(bt) a where exists (
select 1 from log partition(bt) b wherea.userid = b.userid and a.createtime=b.createtime and a.rowid > b.rowid);
回复

使用道具 举报

千问 | 2011-11-1 16:26:29 | 显示全部楼层
not exist似乎效率也不会高多少吧。
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行