Q: get a distinct count based on a case condition I had a problem that I am not able to solve in one query. I want to find all distinct user_ids that  satisfy policy = 'disable' and multiply them by 9. Is it possible to do in one query? I am  struggling to find such a query.
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


A: I think you want:
     count(distinct CASE WHEN policy = 'disable' then user_id end) *9 as disabled_accounts
from table
group by txn_week;

