1. 程式人生 > >查詢oracle資料庫是否有重複資料(根據多個欄位判斷)

查詢oracle資料庫是否有重複資料(根據多個欄位判斷)

根據多個欄位查詢重複資料的總條數:

sql = "select count(*) from tablea a where (a.askname, a.atime) in (select askname,atime from tablea group by askname,atime having count(*)>1) and askrepid not in (select min(askrepid) from tablea group by askname,atime having count(*)>1)"
cursor.execute(sql)
conn.commit()
tables = cursor.fetchall()
print 'result*********:',tables