case when then else end
来源:互联网 发布:各网络宽带资费标准 编辑:程序博客网 时间:2024/04/28 08:56
一、
(行遍历问题,面试)一道SQL语句面试题,关于group by
表内容:bs
bsrq res
2005-05-09 胜
2005-05-09 胜
2005-05-09 负
2005-05-09 负
2005-05-10 胜
2005-05-10 负
2005-05-10 负
二、查询
1、select case when condition then result [when....][else result] end。
case子句可以用于任何表达式可以有效存在的地方。condition是一个返回boolean的表达式。如果结果为真,那么case表达式的结果就是符合条件的result;如果结果为假,那么以相同方式搜寻任何随后的when子句。如果没有when condition为真,那么case表达式的结果就是在else子句里的值。如果省略了else子句而且没有匹配的条件,结果为null。
select bsrq,'胜'=sum(case when res='胜' then 1 else 0 end),
'负'=sum(case when res='负' then 1 else 0 end)
from bs group by bsrq
2、这个简单的case表达式是上面的通用形式的一个特殊的变种。
case expression when value then result [when] [else result] end
先计算expression的值,然后与所有在when子句里声明的value对比,直到找到一个相等的。如果没有找到匹配的,则返回在else子句里的result(或者null)。
select bsrq,'胜'=sum(case res when '胜' then 1 else 0 end),
'负'=sum(case res when '负' then 1 else 0 end)
from bs group by bsrq
- 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函数 case when then when then else end
- sql case when then else end
- Case When then else end-----生成统计表
- [ORACLE] case when then else end 应用
- Sql语句-case when then else end
- 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误。未找到或无法访问服务器。请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接。 (provider: SQL
- 数理逻辑:谓词演算(16)马尔采夫定理
- httplib python3
- 同类不同对象造成的问题
- 基于Tomcat的WebSocket
- case when then else end
- 做事
- C++中虚函数工作原理和(虚)继承类的内存占用大小计算
- 在iPhone应用的table cell中添加自定义布局view
- 编程实现两个正整数的除法
- 常用软件下载地址
- windows平台实现http/https客户端
- ubuntu12.04 server 源
- 【php】缓存类的编写:支持文件缓存和memcache缓存