今天改SQL用到了就搜了搜,现在记下来。

case

when tableName.type in (1,2,3,4)

and tableName.state  in (5,6)

then 1

when tableName.type in (7,8)

and tableName.state in (9,10)

then 1

else 0

end

如果要用到聚合函数就可以如

sum (

case

when tableName.type in (1,2,3,4)

and tableName.state  in (5,6)

then 1

when tableName.type in (7,8)

and tableName.state in (9,10)

then 1

else 0

end

) review

mysql case when then else end 写法的更多相关文章

  1. MySQL查询不区分大小写的sql写法

    MySQL查询不区分大小写的sql写法 mysql查询默认是不区分大小写的 如: select * from some_table where str=‘abc'; select * from som ...

  2. 阳性比例 mysql CASE UNION ALL

    阳性比例 mysql CASE UNION ALL SELECT t.*,t.type_0/all_ FROM ( SELECT FROM_UNIXTIME(create_time,'%Y-%m-%d ...

  3. mysql case when then else end 的写法

    select t.colum1,t.colum2 (case when t.colum1 = '' then '' t.when colum2 = '' then '' else '' end ) a ...

  4. mysql case....when条件

    oracle的写法SELECT decode(ttype,1,’a',2,’b',3,’c',’d') FROM taba 可以在mysql里写成SELECT if(ttype=1, 'a',if(t ...

  5. mysql case when

    下面为您举例说明了三种mysql中case when语句的使用方法,供您参考学习,如果您对mysql中case when语句使用方面感兴趣的话,不妨一看. 1. select name, case w ...

  6. mysql case when 条件过滤

    [1].[代码] 使用CASE WHEN进行字符串替换处理 跳至 [1] [2] [3] [4] ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2 ...

  7. mysql case when group by实例

    mysql 中类似php switch case 的语句. select xx字段, case 字段 when 条件1 then 值1 when 条件2 then 值2 else 其他值 END 别名 ...

  8. mysql case的语法

    测试表:team 第一种语法: CASE case_value WHEN when_value THEN statement_list [WHEN when_value THEN statement_ ...

  9. mysql case 列名 when 和 case when的区别

    最近写了一个sql,才发现有些情况不能用case 列名 when ( and then and and 7.9 then '中' else '差' END ) score_type, 我发现这样写查出 ...

随机推荐

  1. 网络编程-----IO

    IO模型介绍 阻塞IO 非阻塞 多路复用 异步 IO模型比较分析 selectors 阻塞IO:之前写的所有的socket,recv,accput都是 阻塞原理: 其实多数时间多用到了等待数据那里. ...

  2. Linux 测试常用命令

    ls :列出文件 ls -l ls -t  按时间排序 ls -rt 按时间倒序 ls -a  列出所有文件(包括隐藏的) ll : ll = ‘ls -l ’ cd: 进入文件目录 cd 不带目录名 ...

  3. mybatis插入数据后返回对象id

    1.插入的为对象,成功插入后,会返回到指定的字段id中,@Options(useGeneratedKeys=true,keyColumn="id").

  4. c——根据天数输出日期

    <c语言程序设计>(第三版)何钦铭 P190 #include<stdio.h> void month_day(int year,int yearday,int *pmonth ...

  5. angular引用echarts插件

    方法一 1. 命令行下载 npm install echarts --savenpm install ngx-echarts --save 2. angular.json 配置echarts路径. 2 ...

  6. 运行gunicorn失败:[ERROR] Connection in use: ('0.0.0.0', 8000)

    参考:https://pdf-lib.org/Home/Details/5262 执行命令:gunicorn -w 4 -b 0.0.0.0:8000 wsgi:app,遇到如下错误: [2019-0 ...

  7. python_字符编码&格式化

    电脑最小储存单位是bit(位),8bit为一个Byte(字节), 8bit=1Byte 1024Byte=1KB 1024KB=1MB 1024MB=1GB 1024GB=1TB 编码的故事: 计算机 ...

  8. k8s-YAML配置文件(转)

    转自http://www.cnblogs.com/bigberg/p/9203619.html 一.YAML基础 YAML是专门用来写配置文件的语言,非常简洁和强大,使用比json更方便.它实质上是一 ...

  9. SQL查:询结果区分大小写

    在MS SQL2005中的方法: 1)select * from user where name collate Chinese_PRC_CS_AS like 'A$%B%' escape '$'; ...

  10. Spark程序运行常见错误解决方法以及优化

    转载自:http://bigdata.51cto.com/art/201704/536499.htm Spark程序运行常见错误解决方法以及优化 task倾斜原因比较多,网络io,cpu,mem都有可 ...