In the following code, am I correct in thinking that SQL will group both the numerator AND the denominator by “date”, then perform the individual calculations?

select

date(created_at),

round(sum(price) / count(distinct user_id), 2) as arppu

from purchases

where refunded_at is null

group by 1

order by 1;

If so, when I want to group by ONLY the numerator, does the denominator have to be within a sub query, as in the following code?:

Select name, round(sum(amount_paid) /

(select sum(amount_paid) from order_items)

100.0, 2) as pct

from order_items

group by 1

order by 2 desc;

Thanks!