sql - Find the user with the most contact -
Users send messages in each other message box, find a user, which most other users know (get and Send ??)
/ li>
A user can send and receive, so who knows other users (Send and receive by ??) < / P>
Using SQL Server 2005+, CTE:
As with usr_list (SELECT x.user_id, select x.message_from_user as tab x union for other user y.user_id, y.message_to_user as other_user tab Y) SELECT TOP 1 ul.user_id, COUNT ( *) AS Un-CTE's equivalent: num_friends as
SELECT TOP 1 ul.user_id, COUNT (node CTE equivalent:
*) FROM (SELECT x.user_id, x.message_from_user as other_user from table x UNION SELECT y.user_id, y.message_to_user as other_user table) and UL by UL Group Num_friends DESC
Comments
Post a Comment