View a markdown version of this page

INTERSECT 쿼리 예 - Amazon Redshift

Amazon Redshift는 2026년 6월 30일 이후에 Python UDF 사용을 더 이상 지원하지 않습니다. 해당 조치는 단계적으로 시행될 예정입니다. Python 수명 종료 및 마이그레이션 옵션에 대한 자세한 내용은 2025년 6월 30일에 게시된 블로그 게시물을 참조하세요.

INTERSECT 쿼리 예

다음 예를 첫 번째 UNION 예와 비교해 보십시오. 두 예에서는 사용되는 설정 연산자만 다를 뿐이지만, 그 결과는 매우 상이합니다. 다음과 같이 행들 중 하나만 같습니다.

235494 | 23875 | 8771

이 행이 양쪽 테이블에서 발견된 5개 행의 제한된 결과에 있는 유일한 행입니다.

select listid, sellerid, eventid from listing intersect select listid, sellerid, eventid from sales order by listid desc, sellerid, eventid limit 5; listid | sellerid | eventid --------+----------+--------- 235494 | 23875 | 8771 235482 | 1067 | 2667 235479 | 1589 | 7303 235476 | 15550 | 793 235475 | 22306 | 7848 (5 rows)

다음 쿼리는 3월에 뉴욕과 로스앤젤레스의 두 도시에서 모두 현장에서 이루어진 (티켓이 판매된) 이벤트를 찾습니다. 두 쿼리 표현식의 차이점은 VENUECITY 열에 대한 제약 조건입니다.

select distinct eventname from event, sales, venue where event.eventid=sales.eventid and event.venueid=venue.venueid and date_part(month,starttime)=3 and venuecity='Los Angeles' intersect select distinct eventname from event, sales, venue where event.eventid=sales.eventid and event.venueid=venue.venueid and date_part(month,starttime)=3 and venuecity='New York City' order by eventname asc; eventname ---------------------------- A Streetcar Named Desire Dirty Dancing Electra Running with Annalise Hairspray Mary Poppins November Oliver! Return To Forever Rhinoceros South Pacific The 39 Steps The Bacchae The Caucasian Chalk Circle The Country Girl Wicked Woyzeck (16 rows)