美文网首页
mysql case when用法

mysql case when用法

作者: setone | 来源:发表于2018-10-15 11:03 被阅读0次

如图,是一张表格数据


image.png

我们需要求出每天的胜负次数


image.png

我们的sql语句是

select 
t.time as '时间'
,SUM(case    when t.result='胜' then 1 else  0  END) as '胜' 
,SUM(case    when t.result='负' then 1 else  0 END) as '负' 
 from tab t GROUP BY t.time;

相关文章

网友评论

      本文标题:mysql case when用法

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