【发布时间】:2022-01-19 17:52:19
【问题描述】:
我一直在尝试拉动所有月份交易金额大于 1000 的客户。这是我到目前为止所尝试的。但是,当我进行个人客户测试时,它似乎不起作用。
Select customer
,extract(month from trans_date) as mth
,extract(year from trans_date) as yr
,sum(trans_amount) as amt
, case when mth in (8) and amt > 1000 then 1 else 0 end as aug
, case when mth in (9) and amt > 1000 then 1 else 0 end as sep
, case when mth in (10) and amt > 1000 then 1 else 0 end as oct
, case when mth in (11) and amt > 1000 then 1 else 0 end as nov
, case when mth in (12) and amt > 1000 then 1 else 0 end as de_c
from transaction
group by 1,2,3
having (aug = 1 and sep = 1 and oct=1 and nov=1 and de_c = 1)
【问题讨论】:
-
任何给定的行都只有一个第 m 个值,因此您的 HAVING 条件永远不会为真。
-
您的预期结果集到底是什么?