set statement_timeout=0;
explain analyze
delete From book_detail a where a.id = any(array (
select id from (
select id,bill_id,account_book_id, row_number() over(partition by bill_id,account_book_id order by id desc) as rank from book_detail
where sell_date BETWEEN '2018-12-01' and '2018-12-31'
) a where a.rank > 1
)
) and a.sell_date BETWEEN '2018-12-01' and '2018-12-31';
postgresql 删除重复数据
最新推荐文章于 2024-10-04 07:22:19 发布
本文详细解析了一段复杂的SQL删除语句,该语句通过使用子查询和窗口函数row_number()来找出并删除指定日期范围内重复的数据记录。具体操作包括设置语句超时、分析执行计划、从book_detail表中删除特定条件下的重复项。
1376

被折叠的 条评论
为什么被折叠?



