회사에서 접한 쿼리를 이용한 SQL 문제풀이.
문제1
SELECT *
FROM (
SELECT '1' AS A
FROM DUAL
UNION ALL
SELECT '2' AS A
FROM DUAL
UNION ALL
SELECT '3' AS A
FROM DUAL
) M
WHERE NOT EXISTS (
SELECT 1
FROM (
SELECT '1' AS A
FROM DUAL
UNION ALL
SELECT '2' AS A
FROM DUAL
UNION ALL
SELECT '3' AS A
FROM DUAL
) X
WHERE X.A < M.A
)
not exists의 개념을 이해하고 있어야 풀 수 있다.
정답 :
더보기
1
문제2
SELECT *
FROM (
SELECT '1' AS A
FROM DUAL
UNION ALL
SELECT '2' AS A
FROM DUAL
UNION ALL
SELECT '3' AS A
FROM DUAL
UNION ALL
SELECT '4' AS A
FROM DUAL
UNION ALL
SELECT '6' AS A
FROM DUAL
) M
WHERE NOT EXISTS (
SELECT 1
FROM (
SELECT '2' AS A
FROM DUAL
UNION ALL
SELECT '3' AS A
FROM DUAL
UNION ALL
SELECT '4' AS A
FROM DUAL
UNION ALL
SELECT '5' AS A
FROM DUAL
) X
WHERE X.A > M.A
)
정답 :
더보기
6
'SQL' 카테고리의 다른 글
[SQL 쿼리 속도] JOIN 조건 추가보다 UNION ALL이 빠를 수 있다 (3) | 2021.07.14 |
---|---|
[Oracle/Tibero] 특정연도부터 올해까지의 목록 출력 (0) | 2020.07.23 |
[Oracle/Tibero] 콤보에 '전체' 추가해서 기본값으로 세팅하기 (0) | 2020.07.23 |
[MSSQL] ISNULL의 기초 이해 (0) | 2020.06.26 |
[MSSQL] 검색 조건에 LIKE와 컬럼명을 이용하는 쿼리문 (0) | 2020.04.17 |
댓글