架构和插入语句:
create table salarytable (id int, name varchar(50), dept varchar(50), salary int);
insert into salarytable values(100 ,'nikhil','prod', 12000 );
insert into salarytable values(100, 'nikhil', 'prod', 12000);
insert into salarytable values(200, 'john', 'HR', 10000);
insert into salarytable values(200, 'john', 'HR', 10000);
删除查询:
DELETE FROM salarytable
WHERE rowid not in
(SELECT MIN(rowid)
FROM salarytable
GROUP BY id ,name ,dept ,salary);
选择查询:
select * from salarytable;
输出:
| ID |
NAME |
DEPT |
SALARY |
| 100 |
nikhil |
prod |
12000 |
| 200 |
john |
HR |
10000 |
db小提琴here
使用 row_number() 删除重复项
使用 row_number() 删除查询:
delete from salarytable
where rowid in
( select rwid
from ( select rowid rwid
, row_number() over ( partition by id order by id) rn
from salarytable
)
where rn>1
)
选择查询:
select * from salarytable;
输出:
| ID |
NAME |
DEPT |
SALARY |
| 100 |
nikhil |
prod |
12000 |
| 200 |
john |
HR |
10000 |
db小提琴here