还是比较常用的.
就是当xx 然后 xx 或者xx 结束。
- 表中有A B C三列,用SQL语句实现:当A列大于B列时选择A列否则选择B列,当B列大于C列时选择B列否则选择C列
- select (case when a > b then a else b end), (case when b > c then b else c end) from 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 tmp
group by rq