获取整行的列上的MySql最大值

时间:2015-12-08 19:48:45

标签: mysql

表'teams_members'

  • Team_id
  • USER_ID

表'users_playeraccounts'

  • USER_ID
  • Rank_solo
  • Summoner_name

表'用户'

  • 编号
  • 用户名

我的目标:使用召唤者名称和rank_solo获取当前团队成员,其中rank_solo是所有游戏中最高的

因此'users_playeraccounts'中的多个条目可以属于单个用户。

Select user_id,summoner_name,rank_solo 
    from teams_members t 
       join users_playeraccounts p on t.user_id = p.user_id  
       join users u on u.id = p.user_id 
    where team_id = 103

添加了一些内容我不知道

1 个答案:

答案 0 :(得分:0)

试试这个

select a.username, u.rank_solo, u.summoner_name 
    from teams_members as t 
    inner join users_playeraccounts as u on t.user_id = u.user_id 
    inner join users as a on a.id in (select u.user_id  from users_playeraccounts
                                           group by u.summoner_name, 
                                           having max(u.rank_solo) );