More Subqueries Quizzes
Above is the ERD for the database again - it might come in handy as you tackle the quizzes below. You should write your solution as a subquery or subqueries, not by finding one solution and copying the output. The importance of this is that it allows your query to be dynamic in answering the question - even if the data changes, you still arrive at the right answer.
Provide the name of the sales_rep in each region with the largest amount of total_amt_usd sales.
SELECT * FROM(SELECT rname rname,MAX(totalsum) totalsumFROM(SELECT r.name rname,s.name sname,SUM(total_amt_usd) totalsumFROMaccounts aJOINorders oON o.account_id =a.idJOINsales_reps sON a.sales_rep_id =s.idJOINregion rON r.id =s.region_idGROUP BYr.name,s.nameORDER BY 1,3 desc) su