mysql if,case,count()加条件用法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_22222499/article/details/79968490

1.case语法
CASE case_value
WHEN when_value THEN statement_list
[WHEN when_value THEN statement_list] …
[ELSE statement_list]
END CASE

select CASE age when age>30 then 'boy' ELSE 'girl' end as sex from people

2.IF(expr1,expr2,expr3)

expr1条件为真,返回expr2,否则返回expr3

3.count()加条件,统计大于20的

select count(IF(age>20,true,null)) as m from people
阅读更多

没有更多推荐了,返回首页