求一条SQL语句

aoyihuashao 2012-09-17 10:52:24
A表中有两个列C1,C2
按照C1分组,
每组按C2排序,删除超过200条的记录

数量级:百万-千万

最好用一条SQL语句搞定。

...全文
142 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ssqtjffcu 2012-09-17
  • 打赏
  • 举报
回复
什么意思,你看懂我的语句是什么意思了么。如果没看懂就不要乱用我的语句,把数据删了到时找不回来可别找我。。。[Quote=引用 2 楼 的回复:]
这个 r 恒为1


引用 1 楼 的回复:
SQL code


create table temp as select c1,c2 from (select c1,c2,row_number() over (partition by c1 order by c2) r from a) where r<=200;
drop table from a;
rename temp t……
[/Quote]
aoyihuashao 2012-09-17
  • 打赏
  • 举报
回复
明白了,是对的。我数据弄反了。

[Quote=引用 1 楼 的回复:]
SQL code


create table temp as select c1,c2 from (select c1,c2,row_number() over (partition by c1 order by c2) r from a) where r<=200;
drop table from a;
rename temp to a;

一条语句的话。。
delete fr……
[/Quote]
aoyihuashao 2012-09-17
  • 打赏
  • 举报
回复


这个 r 恒为1

[Quote=引用 1 楼 的回复:]
SQL code


create table temp as select c1,c2 from (select c1,c2,row_number() over (partition by c1 order by c2) r from a) where r<=200;
drop table from a;
rename temp to a;

一条语句的话。。
delete fr……
[/Quote]
ssqtjffcu 2012-09-17
  • 打赏
  • 举报
回复

create table temp as select c1,c2 from (select c1,c2,row_number() over (partition by c1 order by c2) r from a) where r<=200;
drop table from a;
rename temp to a;

一条语句的话。。
delete from a
where rowid in
(select rowid, row_number() over(partition by c1 order by c2) r
from a)
where r > 200;
aoyihuashao 2012-09-17
  • 打赏
  • 举报
回复
呵呵,没事的,肯定要现在测试数据上试试的么,
不然咋会有A表C1列呢

关键是这行这种用法我不会么
row_number() over (partition by c1 order by c2) r
看样子是
partition by c1 :按C1分组
order by c2 :按C2排序
row_number() over (partition by c1 order by c2) r 是取这个需要

[Quote=引用 4 楼 的回复:]
什么意思,你看懂我的语句是什么意思了么。如果没看懂就不要乱用我的语句,把数据删了到时找不回来可别找我。。。

引用 2 楼 的回复:
这个 r 恒为1


引用 1 楼 的回复:
SQL code


create table temp as select c1,c2 from (select c1,c2,row_number() over (partition by c1 o……
[/Quote]

17,382

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧