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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度