douyu0725 2014-01-16 07:34
浏览 41
已采纳

PHP / MYSQL语句因此选择Max Sum of Join

I have Problems with a select statement, as a little help here are the important columns:


Table1            
ID NAME           

TABLE 2  
ID U_ID COUNTER

The ID of Table 1 Matches the U_ID of Table 2. Table 2 contains many entries for the same u_id.

What I want to do is to get the Name of the "user" (table 1) who has in sum the max. counter.

What I got since now is the join of the tables (Where clause depends on other rows which are not important for the problem).

Can anyone help me on this issue?

  • 写回答

3条回答 默认 最新

  • dongpu5874 2014-01-16 07:43
    关注
    SELECT name,
          SUM(counter) as counter
    FROM table1
    JOIN table2
    ON table1.id = table2.u_id
    GROUP BY u_id
    ORDER BY counter DESC 
    LIMIT 1 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题