【发布时间】:2018-12-19 23:16:14
【问题描述】:
我使用子查询编写了一个查询,但我想知道是否有任何方法可以仅使用内部连接(或其他连接)来编写它,因为它更有效。
/*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)
提前致谢。
【问题讨论】:
标签: sql sql-server inner-join