標籤:row_number over 第一條 oracle
看看以前的私密日誌,原來自己之前被很多小而簡單的問題困惑過!
看著那時候我們還是新手中的新手做的備忘筆記!
其實就是用了Oracle的統計函數而已!
以前的日記(看樣子應該是以前公司的源碼,呵呵……)如下:勿噴!
對多資料進行分組排序後取每組第一條記錄:
SELECT * FROM ( SELECT ROW_NUMBER() OVER( PARTITION BY ZA40011_3.URIAGE_DENPYO_NO,ZA40011_3.URIAGE_DENPYO_ROW_NO ORDER BY ZA40011_3.KAKUTEI_SURYO_CS, ZA40011_3.KAKUTEI_SURYO_BL, ZA40011_3.KAKUTEI_SURYO_BT, ZA40011_3.SYUKKA_SHIJI_NO, ZA40011_3.SYUKKA_SHIJI_ROW_NO DESC) LEV, ZA40011_3 .* FROM WT_001_ZA40011_22070_2 ZA40011_2, WT_001_ZA40011_22070_3 ZA40011_3, JT_GYOMU_URIAGE_DETAIL URIAGE_DETAIL WHERE ZA40011_2.KAISYA_CODE = URIAGE_DETAIL.KAISYA_CODE AND ZA40011_2.URIAGE_DENPYO_NO = URIAGE_DETAIL.URIAGE_DENPYO_NO AND ZA40011_2.URIAGE_DENPYO_ROW_NO = URIAGE_DETAIL.ROW_NO AND URIAGE_DETAIL.KAISYA_CODE = ZA40011_3.KAISYA_CODE AND URIAGE_DETAIL.URIAGE_DENPYO_NO = ZA40011_3.URIAGE_DENPYO_NO AND URIAGE_DETAIL.ROW_NO = ZA40011_3.URIAGE_DENPYO_ROW_NO AND ZA40011_3.KEPPIN_RIYU_CODE IS NOT NULL ) WHERE LEV = 1-- ORDER BY KAKUTEI_SURYO_CS DESC