美文网首页
sql之合理使用sum case

sql之合理使用sum case

作者: ssttIsme | 来源:发表于2019-03-22 01:20 被阅读0次
    SELECT TIME 时间,
    (SELECT COUNT(result) FROM game g WHERE result='胜' AND  g.time=game.`time`) 胜,
    (SELECT COUNT(result) FROM game g WHERE result='负' AND  g.time=game.`time`) 负
    FROM game GROUP BY TIME;
    
    SELECT TIME 时间,
    SUM(CASE WHEN result='胜' THEN 1 ELSE 0 END) 胜,
    SUM(CASE WHEN result='负' THEN 1 ELSE 0 END) 负
    FROM game GROUP BY TIME;
    

    相关文章

      网友评论

          本文标题:sql之合理使用sum case

          本文链接:https://www.haomeiwen.com/subject/hejkvqtx.html