Azure SQL 数据仓库上的多列 IN / NOT IN 子查询

Multi-column IN / NOT IN subquery on Azure SQL data warehouse

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 ','.

是否有将查询重写为具有内连接或外连接的派生表的解决方法?

具有 IN / NOT IN 子查询的单列有效:

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 )
;

SQL 服务器从来不支持这种(方便的)语法。解决方法是使用 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
)
;

大卫