sum(case when ... then end) 使用
来源:互联网 发布:查看oracle端口 编辑:程序博客网 时间:2024/05/21 11:36
统计国家性别人口
有如下数据
国家(country) 性别(sex) 人口(population)
中国 1 340
中国 2 260
美国 1 45
美国 2 55
加拿大 1 51
加拿大 2 49
英国 1 40
英国 2 60
按照国家和性别进行分组,得出结果如下
国家 男 女
中国 340 260
美国 45 55
加拿大 51 49
英国 40 60
SELECT country, sum( CASE WHEN sex = 1 THEN population END ) as men, sum( CASE WHEN sex = 2 THEN population END ) as womenFROM cGROUP BY country
统计每个人及格和不及格的科目数目
a chinese 100
a math 90
a english 95
b chinese 90
b math 80
b english 100
c chinese 120
c math 70
c english 60
SELECT a.name, count(case when score > 90 then a.name end), count(case when score <= 90 then a.name end)FROM aINNER JOIN b on a.`subject` = b.`subject`group by a.name
0 0
- sum(case when ... then end) 使用
- case when then end
- case when then end
- mysql case when then 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
- 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
- Case when then else end
- case when then else end
- case when then else end
- 补间动画
- asp.net mvc关于提供的防伪标记适用于其他基于声明的用户,而不适用于当前用户错误的处理
- JavaScript 面向对象与基于对象
- 【HDU5924 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 C】【水题】Mr. Frog’s Problem
- Ruby rails 安装错误
- sum(case when ... then end) 使用
- win10系统中安装debian8.6虚拟机,解决共享粘贴板问题
- 总结出的14条编程经验
- 如何手动完成一次APK打包?----APK编译全过程
- 万字长文讲述:任正非,“血洗”华为
- 单点登录原理和java实现简单的单点登录
- 【HDU5925 2016CCPC东北地区大学生程序设计竞赛 - 重现赛 D】【离散化 BFS】Coconuts 大地图少数坏点输出每个联通块的大小
- C++每日一练(STL_Queue)
- 单源最短路问题 Bellman-Ford算法