答案 0 :(得分:1)
嗯。 。 。这似乎符合您的描述:
select date_trunc('month', day), category,
sum(transaction_amount), count(distinct user_id)
from (select d.*,
min(category) over (partition by userid, date_trunc('month', day)) as min_category,
max(category) over (partition by userid, date_trunc('month', day)) as max_category
from daily d
) d
where min_category <> max_category -- at least two categories
group by date_trunc('month', day), category;