'How to use group by and ordery by with some operation in SQL? [closed]

I have two columns price and sold_count for the product table. How do write sql query to find the top 3 shops having highest Revenue (calculate revenue as price*sold_count).

I have following table:

enter image description here



Solution 1:[1]

Use group by shop, order by the sum() of revenues for each group and limit to 3:

select shop 
from yourtable
group by shop
order by sum(price * sold_count) desc
limit 3;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1