MySQL Получить значения, строк с которыми больше всего.

Discussion in 'PHP' started by Mr.Snuffer, 17 Nov 2011.

  1. Mr.Snuffer

    Mr.Snuffer Member

    Joined:
    2 Jul 2010
    Messages:
    140
    Likes Received:
    13
    Reputations:
    0
    Если возможно - в сортированном виде.

    Пример:

    Таблица:

    __|_login__|_inviter___|
    --------------------------------
    1_|_user1_|_user_____|
    2_|_user3_|_user_____|
    3_|_user__|_login_____|
    4_|_user2_|_user_____|
    5_|_user4_|_login_____|

    В итоге я должен получить

    1 - user
    2 - login
     
  2. nikp

    nikp Banned

    Joined:
    19 Sep 2008
    Messages:
    328
    Likes Received:
    591
    Reputations:
    764
    Code:
    select inviter from (select inviter,count(inviter)k from table group by inviter)n order by k desc limit 2
     
    1 person likes this.
  3. Mr.Snuffer

    Mr.Snuffer Member

    Joined:
    2 Jul 2010
    Messages:
    140
    Likes Received:
    13
    Reputations:
    0
    Хера себе oO

    Спасибо!
     
  4. Melfis

    Melfis Elder - Старейшина

    Joined:
    25 Apr 2011
    Messages:
    505
    Likes Received:
    105
    Reputations:
    53
    Code:
    SELECT concat_ws(' - ',count(*),inviter) FROM table group by inviter order by 1 limit 2
    Так попроще запрос будет...
     
    2 people like this.
Loading...
Similar Threads - MySQL Получить значения
  1. GAiN
    Replies:
    3
    Views:
    7,522