您如何为 Amazon redshift 数据库编写查询,以便相关查询的 where 子句具有两个条件?

How can you write a query for Amazon redshift database such that the where clause of the correlated query has two conditions?

例子-

SELECT date, name, 
       (SELECT value
        FROM this_table
        WHERE col1= 'test1' and col2='test'
       ) AS num_sloths_bought_before
FROM source_table;

当我在 redshift 中执行查询时,出现此错误 -

[Amazon](500310) Invalid operation: This type of correlated subquery pattern is not supported yet;

您通常可以使用连接重写相关标量子查询,对于您的查询,它是左连接:

SELECT date, name, dt.value AS num_sloths_bought_before
FROM source_table
LEFT JOIN
 ( SELECT val, 
      value
   FROM this_table
   WHERE col2='test'
 ) this_table
ON source_table.val= this_table.val;