SQL Sub-queries - Percentage Revenue


#1

I have finished the 2 previous SQL courses and I must say they were pretty interesting but from all the concepts, sub-queries are still a bit shakey for me. I am here to ask for your precious help :wink:

With regards to the attached exercise below, I really cannot distinguish between 'sum of amount paid per item type' and 'sum of amount paid for all items'. It is presented as if both 'sum(amount_paid)' statements are referring to the same thing however it is obvious that in fact they refer to 2 distinct elements.

I appreciate if you can provide some insight in order for me to understand the structure for this application.


https://www.codecademy.com/courses/sql-analyzing-business-metrics/lessons/advanced-aggregates/exercises/product-sum-ii?action=lesson_resume




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;


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.