Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 案件何时何地_Sql_Amazon Redshift - Fatal编程技术网

Sql 案件何时何地

Sql 案件何时何地,sql,amazon-redshift,Sql,Amazon Redshift,我试图为其中一个when案例编写一个带有where子句的case语句 基本上: Case when status='A' then sum(amount) where recorded_date=ongoing_date when ... else ... where只适用于第一个case语句,所以我不能在 有什么建议吗 我想这可能会有帮助。基本上不使用where,您可以为每种情况在“when”下添加所有必需的条件: CASE WHEN STATUS = 'A' AND recorded_da

我试图为其中一个when案例编写一个带有where子句的case语句

基本上:

Case when status='A' then sum(amount) where recorded_date=ongoing_date
when ...
else ...
where只适用于第一个case语句,所以我不能在


有什么建议吗

我想这可能会有帮助。基本上不使用where,您可以为每种情况在“when”下添加所有必需的条件:

CASE WHEN STATUS = 'A' AND recorded_date=ongoing_date THEN sum(amount)
WHEN STATUS = 'B' THEN ....
ELSE ...

我怀疑你想要:

sum(case when status = 'A' and recorded_date = ongoing_date then amount else 0 end) as sum_a_sameday

编辑您的问题并提供示例数据和所需结果。如果状态来自一个表,记录的日期来自另一个表,正在进行的日期来自第三个表,这是否重要?@user8834780。不,如果联接设置正确,则无所谓。