WITH T AS (
SELECT 'A01' EQPID, 'A01-001' TZID, 5 SQNO FROM DUAL
UNION ALL SELECT 'A01', 'A01-002', 3 FROM DUAL
UNION ALL SELECT 'A01', 'A01-003', 8 FROM DUAL
UNION ALL SELECT 'B02', 'B02-001', 7 FROM DUAL
UNION ALL SELECT 'B02', 'B02-002', 4 FROM DUAL
UNION ALL SELECT 'B02', 'B02-003', 1 FROM DUAL
UNION ALL SELECT 'C03', 'C03-001', 8 FROM DUAL
UNION ALL SELECT 'C03', 'C03-002', 4 FROM DUAL
UNION ALL SELECT 'C03', 'C03-003', 1 FROM DUAL
UNION ALL SELECT 'D04', 'D04-001', 9 FROM DUAL
UNION ALL SELECT 'D04', 'D04-002', 2 FROM DUAL
UNION ALL SELECT 'D04', 'D04-003', 3 FROM DUAL
)
SELECT EQPID, TZID, SQNO FROM T
ORDER BY EQPID, TZID
;
==> 원하는 결과 쿼리
( 부연 설명 )
EQPID컬럼과 TZID컬럼이 PK라면 SQNO가 8 이 존재하는 경우의
목록만 보여주고 싶습니다.
WITH T AS (
SELECT 'A01' EQPID, 'A01-001' TZID, 5 SQNO FROM DUAL
UNION ALL SELECT 'A01', 'A01-002', 3 FROM DUAL
UNION ALL SELECT 'A01', 'A01-003', 8 FROM DUAL
UNION ALL SELECT 'C03', 'C03-001', 8 FROM DUAL
UNION ALL SELECT 'C03', 'C03-002', 4 FROM DUAL
UNION ALL SELECT 'C03', 'C03-003', 1 FROM DUAL
)
SELECT * FROM T
ORDER BY EQPID, TZID ;
끝까지 읽어주셔서 대단히 감사합니다.
|