2016-12-14 5 views
1

Azure SQL 데이터웨어 하우스는 하위 열 구성 IN/NOT IN 다중 열을 지원합니까?Azure SQL 데이터웨어 하우스의 다중 열 IN/NOT IN 하위 쿼리

것은 같은 쿼리를 실행하는 경우 :

select 
    * 
from 
    schema_name.calendar 
where 
    gregorian_date > '1998-01-01' 
and gregorian_date < '1999-01-01' 
and (yr_wk, day_of_wk) not in (select yr_wk, day_of_wk from schema_name.calendar where week = 25) 
; 

select 
    * 
from 
    schema_name.calendar 
where 
    gregorian_date > '1998-01-01' 
and gregorian_date < '1999-01-01' 
and (yr_wk, day_of_wk) in (select yr_wk, day_of_wk from schema_name.calendar where week = 25) 

을;

오류가 발생했습니다.

SQL Error [103010] [S0001]: Parse error at line: 7, column: 14: Incorrect syntax near ','. 
com.microsoft.sqlserver.jdbc.SQLServerException: Parse error at line: 7, column: 14: Incorrect syntax near ','. 

은 내부 또는 외부 조인과 파생 테이블에 쿼리를 다시 작성하는 해결 방법인가?

select 
    * 
from 
    schema_name.calendar 
where 
    gregorian_date > '1998-01-01' 
and gregorian_date < '1999-01-01' 
and (yr_wk) not in (select yr_wk from schema_name.calendar where week = 25) 
; 

select 
    * 
from 
    schema_name.calendar 
where 
    gregorian_date > '1998-01-01' 
and gregorian_date < '1999-01-01' 
and (yr_wk) in (select yr_wk from schema_name.calendar where week = 25) 
; 

답변

3

SQL 서버이 (편리한) 구문을 지원하지 않았다 :/NOT 하위 쿼리 IN과

단일 열이 일을. 해결 방법은 EXISTS/NOT EXISTS 하위 쿼리를 사용하는 것입니다.

예를 들어

select * 
from 
    schema_name.calendar c 
where 
    gregorian_date > '1998-01-01' 
and gregorian_date < '1999-01-01' 
and not exists 
( 
    select * 
    from schema_name.calendar 
    where week = 25 
    and yr_wk = c.yr_wk 
    and day_of_wk = c.yr_wk 
) 
; 

데이비드