我遇到了一个问题,我无法在一个查询中解决。我想找到满足policy ='disable'的所有不同user_ids并将它们乘以9.是否可以在一个查询中执行?我很难找到这样的问题。
txn_week,
SUM(CASE WHEN policy = 'disable' AND COUNT(DISTINCT user_id) THEN 9 ELSE 0 END) as disabled_accounts
from table
group by txn_week
答案 0 :(得分:0)
我想你想要:
count(distinct CASE WHEN policy = 'disable' then user_id end) *9 as disabled_accounts
from table
group by txn_week;