when 如果
then 那么
else 否则
end 结束
SELECT * FROM A WHERE 1=1
AND(
CASE
WHEN (? IN (49))
THEN ttc.toStoreTime <= DATE_SUB(NOW(), INTERVAL 48 HOUR) AND ttc.toStoreTime NOT IN('1970-01-01 00:00:00')
WHEN (? IN (12, 24, 48))
THEN ttc.toStoreTime >= DATE_SUB(NOW(), INTERVAL ? HOUR)
ELSE ttc.toStoreTime <= NOW()
END
)
参考:https://www.cnblogs.com/renpei/p/5485730.html
解释:
SELECT
case -------------如果
when sex='1' then '男' -------------sex='1',则返回值'男'
when sex='2' then '女' -------------sex='2',则返回值'女'
else 0 -------------其他的返回'其他’
end -------------结束
from sys_user --------整体理解: 在sys_user表中如果sex='1',则返回值'男'如果sex='2',则返回值'女' 否则返回'其他’
---用法一:
SELECT
CASE WHEN STATE = '1' THEN '成功'
WHEN STATE = '2' THEN '失败'
ELSE '其他' END
FROM SYS_SCHEDULER
---用法二:
SELECT STATE
CASE WHEN '1' THEN '成功'
WHEN '2' THEN '失败'
ELSE '其他' END
FROM SYS_SCHEDULER