SQL case 语句的实践
来源:互联网 发布:ubuntu没有中文输入法 编辑:程序博客网 时间:2024/05/30 23:49
Case 和聚合函数的组合
select custid, case when opendate>20160101 and opendate<20161231 then count(*) else o end as total from customer_table group by custid, opendate 1
select custid sum(case when opendate>20160101 and opendate<20161231 then 1 else o end ) as total from customer_table group by custid 2
select custid, opendate, case when opendate>20160101 and opendate<20161231 then count(*) else o end as total from customer_table group by custid, opendate 3
注意语句1 是现以custid, opendate做了聚合,再选择部分聚合后的值计算count(*) , 逻辑和语句3一样, 只不过删除了opendate这个列, 此时custid仍有重复值。count(*) 计算的如果满足opendate>20160101 and opendate<20161231的值
语句2 和语句1的相差很大, 相当于对原始行做了过滤( where 处过滤),在进行聚合
这两句是聚合函数的使用位置引起的, 是在case 内部使用,还是在外部使用。
- SQL case 语句的实践
- sql的case语句
- sql的case语句
- SQL的case when语句
- SQL语句中CASE函数的用法
- SQL中case语句的执行
- 一个SQL语句的用法。Case 用法
- SQL语句----CASE WHEN 的用法简介
- SQL语句中 CASE 的用法
- PL/SQL 中 CASE 语句的使用
- SQL语言的CASE语句备忘
- pl/sql的case语句总结
- PL/SQL 中 CASE 语句的使用
- sql中case语句的用法浅谈
- SQl CASE 语句的嵌套使用方式
- SQL的 case when语句嵌套使用
- SQL语句中case when的使用
- sql语句CASE WHEN 的使用
- Linux 定时执行任务命令: at
- Combination Sum II
- UVA-11300
- [Codeforces Round #286 DIV1B (CF506B)] Mr. Kitayuta's Technology
- AngularJS ui.bootstrap.alert 消息
- SQL case 语句的实践
- eclipse设置字体颜色
- bzoj 3630 [JLOI2014]镜面通道 计算几何 网络流
- The dependency `MBProgressHUD` is not used in any concrete target.
- null与undefined
- 新的开始
- jetty项目部署
- 第一篇博客-关于采集来编码的问题
- window caffe 下训练mnist及测试