--如果不要第一列Select
A.EPNAME As name
From
EP A
Inner Join
tel B
On A.EPID = B.EPID
Group By
A.EPNAME, A.EPID
Order By
Count(B.id) Desc, A.EPID
A.EPNAME As name
From
EP A
Inner Join
tel B
On A.EPID = B.EPID
Group By
A.EPNAME, A.EPID
Order By
Count(B.id) Desc, A.EPID
ID = Identity(Int, 1, 1),
A.EPNAME As name
Into #T
From
EP A
Inner Join
tel B
On A.EPID = B.EPID
Group By
A.EPNAME, A.EPID
Order By
Count(B.id) Desc, A.EPIDSelect * From #T
Drop Table #T
from
(select epid from tel group by epid order by count(*) desc)a
left join
EP b on a.epid=b.epid
group by e.epid
order by count(*) desc
(select epid from tel group by epid order by count(*) desc)a
left join EP b
on a.epid=b.epid