它在BigQuery中可以正常运行,但我在MS SQL Server中没有得到正确的信息;
CASE
WHEN COUNT( RSM.RECEIVED_AT BETWEEN DATEADD(day, -84,UDATE.SQLDate) AND UDATE.SQLDate ) >= 1
AND COUNT(SAL.DATE BETWEEN DATEADD(day, -7, UDATE.SQLDate) AND UDATE.SQLDate) >=2
AND COUNT(SAL.DATE BETWEEN DATEADD(day, -14, UDATE.SQLDate) AND DATEADD(day, -7, UDATE.SQLDate)) >= 2
THEN 'True'
ELSE 'False' END AS AVAILABLE
出了什么问题?
答案 0 :(得分:1)
我怀疑你所追求的是:
CASE
WHEN COUNT(CASE WHEN RSM.RECEIVED_AT BETWEEN DATEADD(DAY, -84, UDATE.SQLDate) AND UDATE.SQLDate THEN 1 END) >= 1
AND COUNT(CASE WHEN SAL.[DATE] BETWEEN DATEADD(DAY, -7, UDATE.SQLDate) AND UDATE.SQLDate THEN 1 END) >= 2
AND COUNT(CASE WHEN SAL.[DATE] BETWEEN DATEADD(DAY, -14, UDATE.SQLDate) AND DATEADD(DAY, -7, UDATE.SQLDate) THEN 1 END) >= 2 THEN 'True'
ELSE 'False'
END AS AVAILABLE;
正如我在评论中说的:“ COUNT
(或任何其他聚合函数)中不能有布尔表达式,它需要一个标量表达式。”