sql case when

来源:互联网 发布:windows 查看文件编码 编辑:程序博客网 时间:2024/05/29 15:10

还是比较常用的.

就是当xx 然后 xx 或者xx 结束。

  1. 表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列  
  2.   
  3. select (case when a > b then a else b end), (case when b > c then b else c endfrom table;  


下面一个例子:

select * from tmp


要求求出下列结果:


SELECT sum(case when shengfu='胜' then 1 else 0 end ) as '胜',        sum(case when shengfu='负' then 1 else 0 end ) as '负',       rq from tmpgroup by rq


原创粉丝点击