2016-12-14 10 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 Serverは、この(便利な)構文をサポートしたことはない:/ 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 
) 
; 

デビッド

関連する問題