not in, not exists 사용시 쿼리속도가 느릴때
not in, not exists 사용시 쿼리 속도가 느릴때.
특정 항목을 제외 시키기 위해 not in, not exists를 이용합니다.
단건 몇개의 경우 not in으로 처리하고 다건일 경우에는 not exists를 사용합니다.
속도가 너무 느릴경우엔.
left join을 이용하여 붙이고 null인 항목을 가져오면
제외된 항목을 가져옵니다.
예)
특정 항목을 제외 시키기 위해 not in, not exists를 이용합니다.
단건 몇개의 경우 not in으로 처리하고 다건일 경우에는 not exists를 사용합니다.
속도가 너무 느릴경우엔.
left join을 이용하여 붙이고 null인 항목을 가져오면
제외된 항목을 가져옵니다.
예)
-- not exists로 조회explain extendedselectcount(a.user_id) as cnt,c.chnl_id,c.use_intt_idfrom user_ldgr aleft join use_intt_per_user con a.user_id = c.user_idwhere a.ATHZ_DT < '20160101'and not exists(selectb.user_idfrom lgn_prhs bwhere b.lgn_dt between '20150101' and '20151231'and b.user_id = a.user_idgroup by b.user_id)group by chnl_id;
-- left join로 조회explainselectcount(a.user_id) as cnt,c.chnl_id,c.use_intt_idfrom user_ldgr aleft join use_intt_per_user con a.user_id = c.user_idleft join(selectb.user_idfrom lgn_prhs bwhere b.lgn_dt between '20150101' and '20151231'group by b.user_id) don d.user_id = a.user_idwhere a.ATHZ_DT < '20160101'and d.user_id is nullgroup by c.chnl_id;
댓글
댓글 쓰기