delete from resource_db.ht_sim_party where sim_party_id in ( select sim_party_id from ( select sim_party_id, sim_id, party_id, rnum from ( select distinct sim_party_id, sim_id, party_id, row_number() over (partition by party_id) as rnum from resource_db.ht_sim_party where ht_sim_party.from_date <= localtimestamp(0) and localtimestamp(0) < ht_sim_party.to_date and '2016-05-30' < ht_sim_party.from_date ) as foo where rnum > 1 ) as bar )