--如果不要第一列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

解决方案 »

  1.   

    --如果需要第一列,借助臨時表Select
    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
      

  2.   

    select EPID,EPNAME from EP a where EPID in (select distinct EPID from tel) order by (select count(epid) from tel where epid = a.epid)
      

  3.   

    select a.epid,b.epname 
    from 
    (select epid from tel  group by epid order by count(*) desc)a
    left join
    EP b on a.epid=b.epid
      

  4.   

    select t.ID,e.epname as name from ep e innert join tel  t on t.epid=e.epid
     group by e.epid 
     order by count(*) desc
      

  5.   

    select a.epid,b.epname from 
    (select epid from tel  group by epid order by count(*) desc)a
    left join  EP b 
    on a.epid=b.epid