我创建了一个查询来删除表中的重复行。我尝试这样做,但输出是“值太多”
DELETE FROM Employeetest
WHERE employeeid IN (SELECT
employeetest.*,
ROW_NUMBER() OVER (PARTITION BY employeeid ORDER BY employeeid) AS rownumber
FROM
employeetest
HAVING
(rownumber > 1));
我也做过
SELECT
employeetest.*,
ROW_NUMBER() OVER (PARTITION BY employeeid ORDER BY employeeid) AS rownumber
FROM
employeetest
然后
DELETE * FROM employeetest;
它不工作
最佳答案
你标记为 plsql 我知道你的 DB
是 Oracle
。所以你可以使用 rowid pseudocolumn
如下:
delete Employeetest t1
where rowid <
(
select max(rowid)
from Employeetest t2
where t2.employeeid = t1.employeeid
);
如果目的是删除
employeeid
值的所有重复项。附言不可能以这种方式删除
Delete * from employeetest where ...
,但使用 Delete from employeetest where ...
或 Delete employeetest where ...
是可能的选项。关于sql - 复制 SQL 中的行输出太多值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52913223/