Ds
Ds
the output of a subquery can be listed in the output of the main query
-- find the total number of orders for each customer
Task-3:
select customer.Customer_ID, customer_name, TotalProfit
FROM
customer
inner join
(
SELECT Customer_ID, SUM(profit) AS TotalProfit
FROM market
GROUP BY Customer_ID
) AS CustomerProfits
on CustomerProfits.Customer_ID = customer.Customer_ID
ORDER BY TotalProfit DESC
LIMIT 2;
https://dev.mysql.com/doc/refman/8.4/en/view-updatability.html