2011-12-26 43 views

回答

1

什么组?

从我读到的,你想看到“GROUP” 最受欢迎的friend_ID,但我不确定你的意思是什么组。

所以这给你在整个表中最流行的“Friend_ID”。

Select count(Friend_ID), Friend_ID 
from table 
Group by friend_ID 
Order by count(friend_ID) DESC 
0
select 
     YT1.Person_ID, 
     YT1.FieldA, 
     YT1.FieldB, 
     PreQuery.Popularity 
    from 
     YourTable YT1 
     JOIN (select YT.friend_id, 
         count(*) as Popularity 
        from YourTable YT 
        group by YT.friend_id) PreQuery 
      on YT1.Person_ID = PreQuery.Friend_ID 
    order by 
     PreQuery.Popularity DESC 
相关问题