我使用子查询编写了一个查询,但我想知道是否有任何方法可以只使用内部连接(或其他连接)来编写它,因为这样效率更高。
/*2. List the name of the sales rep who serves the most customers*/
select Sr.REP_NUM, Fname, Lname, count(cust_num) As TotalCustomers from employee Em
inner join SALESREP Sr on Sr.REP_NUM = Em.EMP_Num
inner join Customer Cu on Cu.REP_NUM = Sr.REP_NUM
group by Sr.REP_NUM, fname, lname
having count(Cu.rep_num) = (select max(AllReps.MostReps) from
(select count(rep_num) As MostReps from Customer group by rep_num) As AllReps)
提前谢谢。
https://stackoverflow.com/questions/53860483
复制相似问题