2015-11-28 67 views
0

我想從這個SQL中刪除重複的行,並且兩次產品代碼都通過了。我想從這個SQL的公共數據。我在PostgreSQL數據庫中運行這個SQL。如何從sql中刪除重複的數據

SQL查詢是:

SELECT DISTINCT 
    csi.style_item_id AS id, 
    csi.item_code AS item_code, 
    csi.quantity AS quantity, 
    std_unit.stdum_name AS standard_unit, 
    csi.total_cost AS total_cost, 
    cim.item_name AS item_name, 
    pid.product_code AS product_code 
FROM cm_items_master cim, 
    cm_style_items csi, 
    stdunit_master std_unit, 
    cm_style_ccode_master sccm, 
    cm_style_designer sd, 
    cm_designer_master dm, 
    cm_production_info_details pid 
WHERE pid.style_ccode_id = sccm.style_ccode_id 
    AND csi.cm_item_id = cim.item_id 
    AND csi.std_unit_id = std_unit.id 
    AND csi.style_ccode_id = sccm.style_ccode_id 
    AND sccm.style_ccode_id = sd.style_ccode_id 
    AND sd.designer_id = dm.designer_id 
    AND pid.product_code  IN ( getSplitedPdtCode(productCode)) 
    AND csi.is_delete  = 'N' 
    AND cim.is_delete  = 'N' 
    AND std_unit.is_delete = 'N' 

此SQL返回同一行4次。我不想要重複的數據。

+0

地獄。使用適當的案例等這太複雜了嗎? – frlan

+1

不,不可能出現'select distinct'結果重複的行。你可以請出示一些數據樣本。 – Houari

+1

無關,但:請習慣顯式的'JOIN's,而不是使用'where'子句中的舊的隱式連接 –

回答

0

試試這個查詢,它會幫助你。

​​3210
-1
With CTE_Dup as emp 
    (Select *, row_number() over(partition by Empid order by Empid) as rownumber 
    from employee) 
Delete from emp 
where rownuber > 1 
+1

代碼只有答案質量很低,因爲至少應該有一兩句話向讀者解釋你正在回答什麼問題,以及該代碼以何種方式回答這個問題。見http://meta.stackexchange.com/questions/148272/is-there-any-benefit-to-allowing-code-only-answers-while-blocking-code-only-ques –