在一个表中,我可以顺畅运行
对于每个流程,我必须保持运行次数最多的行,并删除其余所有行。必须对所有流程进行此操作。
使用单个语句。
我尝试使用cte,排名但出现错误。
我尝试按流分组,然后为该组应用等级,然后删除> 1的行。
WITH cte AS
( SELECT flow, RANK() OVER
(PARTITION BY flow ORDER BY runs)
AS rank FROM TEST_RESULTS_TABLE GROUP BY flow )
DELETE FROM cte WHERE rank >1 ;
this is giving :
ORA-00928: missing SELECT keyword
00928. 00000 - "missing SELECT keyword"
*Cause:
*Action:
Error at Line: 25 Column: 153
答案 0 :(得分:2)
Oracle不支持可更新的CTE。相反,您可以执行以下操作:
delete from test_results_table trt
where runs > (select min(trt2.runs)
from test_results_table trt2
where trt2.flow = trt.flow
)
答案 1 :(得分:1)
您可以使用RANK()
查询(不使用GROUP BY
),并使用DELETE
伪列将其与ROWID
语句相关联:
DELETE FROM test_results_table
WHERE ROWID IN (
SELECT ROWID
FROM (
SELECT RANK() OVER ( PARTITION BY flow ORDER BY runs ASC ) AS rnk
FROM test_results_table
)
WHERE rnk > 1
)
db <>提琴here