您好,登錄后才能下訂單哦!
1.OLD:
SELECT card.c_cust_id, card.TYPE, card.n_all_money FROM card WHERE card.c_cust_id NOT IN (SELECT c_cust_id FROM card WHERE TYPE IN ('11', '12', '13', '14') AND flag = '1') AND card.TYPE IN ('11', '12', '13', '14') AND card.flag = 'F';
2.優(yōu)化方向
(1).主查詢和子查詢使用的表相同,條件差不多。考慮進(jìn)行合并。
(2).
使用分析函數(shù)找出相同c_cust_id 既card.flag = 'F' 也 flag = '1' 或者只滿足flag = '1' 然后將這部分記錄過濾掉即可。
當(dāng)分組結(jié)果card.flag = 'F' 也 flag = '1' min(flag) over(partition by card.c_cust_id) = '1'
當(dāng)分組結(jié)果flag = '1' min(flag) over(partition by card.c_cust_id) = '1'
當(dāng)分組結(jié)果flag = 'F' min(flag) over(partition by card.c_cust_id) = 'F' (需要)
select card.c_cust_id, card.TYPE, card.n_all_money from (select card.c_cust_id, card.TYPE, card.n_all_money, min(flag) over(partition by card.c_cust_id) from card where card.TYPE IN ('11', '12', '13', '14') and card.flag in ('1','F')) where card.flag = 'F';
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。