Revenue by product
mediumFor each product with sales, show its name, units sold, and revenue using order item quantity times unit price. Sort by revenue descending, then product name.
Hospital Database · SQLite
Run your SQL answer to see the returned rows and check it.
SELECT p.product_name, SUM(i.quantity) AS units_sold, ROUND(SUM(i.quantity * i.unit_price), 2) AS revenue FROM products AS p JOIN order_items AS i ON i.product_id = p.product_id GROUP BY p.product_id ORDER BY revenue DESC, p.product_name;