포함 시키고 있는 데이터 제거하는 쿼리 질문드려요 0 2 807

by 하울카 [SQL Query] [2018.07.31 19:26:53]


.

 

by 아발란체 [2018.08.01 09:20:33]

 

WITH T AS (
    SELECT 'AAA' AS v1, 'KAO' AS v2 FROM DUAL
    UNION ALL SELECT 'AAA', 'KBO' FROM DUAL
    UNION ALL SELECT 'AAA', 'KAO' FROM DUAL
    UNION ALL SELECT 'BBB', 'KBO' FROM DUAL
    UNION ALL SELECT 'CCC', 'KAT' FROM DUAL
)
SELECT v1, v2 FROM (
    SELECT
        T.*,
        CASE
            WHEN (
                COUNT(*) OVER(PARTITION BY v1) = SUM(DECODE(SUBSTR(v2, 1, 2), 'KA', 1, 0)) OVER(PARTITION BY v1)
            )
            THEN 'true'
            ELSE 'false'
        END AS only_ka
    FROM
        T
) WHERE
    only_ka = 'true'

 


by 우리집아찌 [2018.08.01 10:02:47]
WITH T (COL1 , COL2 )AS (
    SELECT 'AAA', 'KAOITD' FROM DUAL UNION ALL 
    SELECT 'AAA', 'KAIDJA' FROM DUAL UNION ALL 
    SELECT 'AAA', 'KBWSAZ' FROM DUAL UNION ALL 
    SELECT 'AAA', 'KBRWAD' FROM DUAL UNION ALL 
    SELECT 'BBB', 'KAOITD' FROM DUAL UNION ALL 
    SELECT 'BBB', 'KAIDJA' FROM DUAL UNION ALL 
    SELECT 'BBB', 'KBWSAZ' FROM DUAL UNION ALL 
    SELECT 'BBB', 'KBRWAD' FROM DUAL UNION ALL 
    SELECT 'CCC', 'KAOITD' FROM DUAL UNION ALL 
    SELECT 'CCC', 'KAIDJA' FROM DUAL 
    
)

SELECT COL1
     , COL2
  FROM T 
 WHERE COL1 = 'CCC'
   AND REGEXP_LIKE ( COL2 , '^KA' ) 
  
   

 

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입