避免反之亦然重复表中的数据

时间:2016-03-09 06:06:39

标签: sql duplicates oracle-sqldeveloper

我在查询数据时遇到问题。此表包含重复数据,但反之亦然Manner(请参阅下面的屏幕截图以便更好地理解),表中包含两行数据。但是,我希望每个副本只有一行数据。请提出最好的逻辑或方法来解决这个问题。

Screenshot of duplicate records

1 个答案:

答案 0 :(得分:1)

试试这个

select distinct Business_unit, 
case vocher_ID < vocher_ID2 then vocher_ID else vocher_ID2 end as vocher_ID,
vendor_id,name1,invoice_id,pss_invc_id_nospl,gross_amt,business_unit2,
case when vocher_ID < vocher_ID2 then vocher_ID2 else vocher_ID end as vocher_ID2,
vendor from ps_dup_inv_cmp