SQL sum case when then else
来源:互联网 发布:教育公平 知乎 编辑:程序博客网 时间:2024/06/16 03:44
SQL sum case when then else
数据库 t Id Name 胜负 1 张三 胜 2 李四 胜 3 张三 胜 4 张三 负 5 王五 胜 6 赵六 负 Name SF 张三 1 李四 1 张三 1 张三 0 王五 1 赵六 0
Name 胜利的次数 张三 2 李四 1 王五 1 赵六 0 Name 胜利的次数 失败的次数 张三 2 1 李四 1 0 王五 1 0 赵六 0 1
表 b
表内容
要求显示谁胜了几场
select Name, case 胜负 when '胜' then 1 else 0 as SF end from b
显示的内容为
把数字进行加法运算需要用到 sum 是根据Name 合并组的
select Name,sum(case 胜负 when '胜' then 1 else 0 end) as '胜利的次数' from b group by Name
显示的内容为
如果要想把胜利几场和失败几场都显示出来
select Name,sum(case 胜负 when '胜' then 1 else 0 end) as '胜利的次数',sum(case 胜负 when '负' then 1 else 0 end)as '失败的次数' from b group by Name
显示的是
0 0
- SQL sum case when then else
- sql case when then else
- case when then else SQL语句
- case when then else SQL语句
- case when then else SQL语句
- sql case when then else end
- Sql语句-case when then else end
- sql case when then else end
- case when then else
- case when then else
- case when then else
- case when then else
- case when then else end
- case when then else end
- case when then else end
- case+when+then+else+end
- case when then else end
- case when then else end
- selector资源的两种使用方式
- UITableView 中倒计时
- Container With Most Water
- [从零开始学libGDX]前言:关于游戏,关于libGDX,关于自己
- Android Studio简单设置
- SQL sum case when then else
- yum更新源
- 关于webappbuilder for ArcGIS下拉菜单
- C++:STL标准入门汇总
- 黑马day12 DbUtils的介绍
- 黑马程序员——Java基础:枚举
- Animation.setFillAfter and Animation.setFillBefore的作用
- IOS 错误:error: unknown type name 'UIImageView'
- textview字体的高度