dotwc62080 2012-09-26 02:25
浏览 20
已采纳

MySql:选择查询

That is my mat_likes tables:

mat_id| yes| no
  1   | 1  | 0
  1   | 1  | 0
  1   | 1  | 0
  2   | 1  | 0
  3   | 1  | 0
  4   | 1  | 0
  4   | 1  | 0

How can I select mat_id of those materials, which have the most yes = 1. Еxample of subtracting the results:

  1. mat_id = 1, because have total yes = 3
  2. mat_id = 4, because have total yes = 2
  3. mat_id = 3, because have total yes = 1
  4. mat_id = 2, because have total yes = 1
  • 写回答

3条回答 默认 最新

  • dongna1593 2012-09-26 02:29
    关注
    SELECT mat_id,SUM(yes) yes_sum 
    FROM mat_likes 
    GROUP BY mat_id 
    ORDER BY yes_sum DESC
    

    will return a result set with the sum of yes's for each mat_id, with the greatest sums on top!

    edit: added mat_id to the field list

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端