---
title: "postgresql 删除重复数据"
author: "Luob."
date: "2019-01-26T01:19:47Z"
tags: []
categories: ["数据库"]
slug: "postgresql"
draft: false
lastmod: "2019-01-26T01:19:47Z"
id: 2437082
url: "https://takeme.iteye.com/blog/2437082"
---

```sql

set statement_timeout=0;
explain analyze
delete From bill_account_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 bill_account_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'; 

```