我在Redshift中具有以下select语句,如果满足内部条件,它将返回具有某些值的行。我想将其转换为DQ检查,如果没有返回行ae则返回1(真),如果返回任何行则返回0,但是我不知道应该在何处应用case语句。这是select语句:
select * from (select brand,calendar_dt, product,
count(account) count from revenue_base
where player_days = 0 and volume_loc >0 group by brand,calendar_dt, product)
where count > 1000 and calendar_dt >='2020-07-12'
and calendar_dt < '2020-07-13'
您能为此提供一些想法吗?
首先,Redshift支持布尔值,因此case
不需要。其次,对聚合之前的日期进行过滤。这通常更快。
然后,您可以使用having
子句按计数进行过滤,因此不需要子查询:
select not exists (select 1
from revenue_base
where player_days = 0 and volume_loc > 0 and
calendar_dt >= '2020-07-12' and calendar_dt < '2020-07-13'
group by brand, calendar_dt, product
having count(*) > 1000
) as result
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句