I am currently learning SQL and I am required to execute some SQL queries. There is one particular query that I fail to implement.
Which are the clients who have (totally) the most expensive orders?
salesorderid (int) customerid (int) totaldue (double)
1 32000 3.20000
SELECT totaldue, customerid
WHERE totaldue = (SELECT max(totaldue) FROM salesorderheader);
GROUP BY customerid)
this gives biggest expences by clients:
SELECT distinct max(totaldue) over (partition by customerid),customerid FROM salesorderheader order by 1 desc ;
this shows the most wasting client between all:
select sum(totaldue) over (partition by customerid),customerid FROM salesorderheader order by 1 desc limit 1 ;