MySQL中有一个用于判断多种情况的语句,类似于java中的switch…case,在写SQL过程中需要用到case when嵌套,在这里记录一下,以防忘记。
简单例子:
SELECT
WHEN ISNULL(work_order_no) THEN
(CASE WHEN 2 > 1 THEN 11 ELSE 22 END)
(CASE WHEN 1 > 0 THEN 33 ELSE 66 END)
qk_20030102
WHERE
work_order_no = 'GD0000070324'
实际使用的例子:
SELECT
work_order_no,
CASE
WHEN UNIX_TIMESTAMP(
STR_TO_DATE(
chuangjian_time,
'%Y-%m-%d %H:%i:%s'
) > UNIX_TIMESTAMP(
STR_TO_DATE(
CONCAT(
substring(chuangjian_time, 1, 10),
"18:00:00"
'%Y-%m-%d %H:%i:%s'
CASE
WHEN UNIX_TIMESTAMP(
STR_TO_DATE(
substring(chuangjian_time, 1, 10),
'%Y-%m-%d %H:%i:%s'
) + 124200 >= UNIX_TIMESTAMP(
STR_TO_DATE(
yuyue_opt_time,
'%Y-%m-%d %H:%i:%s'
) THEN
CASE
WHEN UNIX_TIMESTAMP(
STR_TO_DATE(
assign_time,
'%Y-%m-%d %H:%i:%s'
) + 5400 >= UNIX_TIMESTAMP(
STR_TO_DATE(
yuyue_opt_time,
'%Y-%m-%d %H:%i:%s'
) THEN
qk_20030102
MySQL中有一个用于判断多种情况的语句,类似于java中的switch…case,在写SQL过程中需要用到case when嵌套,在这里记录一下,以防忘记。简单例子:SELECT CASEWHEN ISNULL(work_order_no) THEN (CASE WHEN 2 > 1 THEN 11 ELSE 22 END)ELSE (CASE WHEN 1 > 0 THEN 33 ELSE 66 END)ENDFROM qk_20030102WHERE work_or
举例如下: 数据表为DemoTable,字段有id, condition1,condition2,condition3,condition4,condition5 要求是查询DemoTable中,condition1,condition2,condition3,condition4,condition5五个字段中符合任意两个或两个以上的条件的内容。 可使用case when来实现这个条件,需要嵌套子查询语句 sql语句代码示例如下: 代码如下: SELECT * FROM DemoTable WHERE ((SELECT CASE 1 WHEN condition1满足条件 THEN 1 E
case when可以嵌套使用,写出更复杂的逻辑实现
select trunc(a.out_date) out_date,
nvl((select x.dept
from neubi_work.dim_dept x...
mysql case when多条件同时满足的多个and组合嵌套的情况,判断空is null --- 系列一 https://blog.csdn.net/qb170217/article/details/81504578
方法一:
SELECT id, time, type,
CASE when (reason is null or reason = '') and type = '驳回...
1、简单的case when语句:
case sex when ’1' then '男' when ’2’ then '女’else ’其他’ end
2、复杂的case when语句:
case when month in (01,02,03)
最近,在学习Hive基础知识时,遇到了遇到了Case When Else End语法,以前学习MySQL时忽略了这部分知识点,现总结一下相关的知识给大家。首先练习一个例子如下:一、学生课程成绩统计1)建表use hiveDemo;
CREATE TABLE `course` (
`id` int,
`sid` int ,
`course` string,
`score`...
SELECTION-SCREENBEGINOFBLOCKB1WITHFRAMETITLETEXT-001.
SELECT-OPTIONS:S_BUKRSFORMATDOC-BUKRS,
S_WERKSFORMATDOC-WERKS.
SELECTION-SCREENENDOFBLOCKB1.
SELECTBUKRS,WERKS,...
select name,
case when CODE='ST' then ... else
(
case when numbers is null then 1 else numbersnew/numbersold end)
as times
from TABLENAME where Condition