1.OLD:
創(chuàng)新互聯(lián)專(zhuān)注于曹妃甸網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供曹妃甸營(yíng)銷(xiāo)型網(wǎng)站建設(shè),曹妃甸網(wǎng)站制作、曹妃甸網(wǎng)頁(yè)設(shè)計(jì)、曹妃甸網(wǎng)站官網(wǎng)定制、成都小程序開(kāi)發(fā)服務(wù),打造曹妃甸網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供曹妃甸網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。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).主查詢(xún)和子查詢(xún)使用的表相同,條件差不多??紤]進(jìn)行合并。
(2).
使用分析函數(shù)找出相同c_cust_id 既card.flag = 'F' 也 flag = '1' 或者只滿(mǎn)足flag = '1' 然后將這部分記錄過(guò)濾掉即可。
當(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';