根据案例条件得到一个明确的计数

时间:2014-01-23 00:20:24

标签: sql

我遇到了一个问题,我无法在一个查询中解决。我想找到满足po​​licy ='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

1 个答案:

答案 0 :(得分:0)

我想你想要:

     count(distinct CASE WHEN policy = 'disable' then user_id end) *9 as disabled_accounts
from table
group by txn_week;