2017-06-30 28 views
0

我有一個表格,其中包含幾列(請參閱附件)的佈局。CASE WHEN與相同的字段

現在你可以看到記錄1和3具有相同「關閉ECL」 ..我想什麼是以往任何時候都具有最高的「TOTAL」保持ECL量和其他記錄(這相同的總有) 「Closing ECL」獲得更新爲0 ..

我該怎麼做?很迷茫.. enter image description here

方案: enter image description here

+0

發佈示例輸出 – mohan111

+0

請在您的問題中添加表格結構和數據作爲文本。不是圖像。如果您嘗試過某些操作,請添加您的查詢。並期待輸出 –

+0

@ mohan111情景發帖 – Laura

回答

0

你可以用update做到這一點:

update t 
    set closingECL = 0 
    where total < (select max(t2.total) 
        from t t2 
        where t2.primary_elf_id = t.primary_elf_id and 
         t2.closingECL = t.closingECL 
       ); 

這假定邏輯是每primary_elf_id應用。

注意:如果最大total是重複的,則所有的最大值保留。

+0

,所以這是自己加入並檢查哪個總數更高並將最低值設置爲0? – Laura

+0

@Laura。 。 。這是一個很好的描述它在做什麼。 –