After playing around a bit I noticed that the code will not work when the “/” is at the beginning on the 2nd line, but it functions fine at the end of the first line. Why is this?
Here is the code for clarity:
select name, round(sum(amount_paid) /
(select sum(amount_paid) from order_items) * 100.0, 2) as pct
group by 1
order by 2 desc;