mysql的case when字段为空,null的问题

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

mysql的case when字段为空,null的问题

我有一个魔盒   2022-12-13 我要评论

mysql的case when字段为空,null

name字段为null时替换为 ‘该字段为空’

SELECT 
CASE 
WHEN name is null THEN '该字段为空'
ELSE name
END as name
,email_id
 FROM mysql_table_name

case when 判断null(已测试)

SELECT
		(case when cdi.DEVICE_TAG is not null then cdi.DEVICE_TAG else '暂无数据' end) as deviceTag,
		(case when cdi.DEVICE_CODE is not null then cdi.DEVICE_CODE else '暂无数据' end) as deviceCode,
		(case when sc.full_name is not null then sc.full_name else '暂无数据' end) as deviceVendor,
		(case when ct.CLASS_NAME is not null then ct.CLASS_NAME else '暂无数据' end) as deviceTypeNameB,
		(case when cdi.DEVICE_PORT is not null then cdi.DEVICE_PORT else '暂无数据' end) as devicePort,
		(case when cdi.CREATE_TIME is not null then cdi.CREATE_TIME else '暂无数据' end) as createTimeStr
-- 			cdi.DEVICE_TAG as deviceTag,
-- 			cdi.DEVICE_CODE as deviceCode,
-- 			sc.full_name as deviceVendor,
-- 			ct.CLASS_NAME as deviceTypeNameB,
-- 			cdi.DEVICE_PORT as devicePort,
-- 			cdi.CREATE_TIME as createTimeStr
		FROM
			con_device_info AS cdi
		LEFT JOIN sys_code AS sc ON sc.code_value = cdi.DEVICE_VENDOR
		LEFT join con_type as ct on ct.ID=cdi.DEVICE_TYPE
		where cdi.ID=#{id}

重点:

case when xxx

is null 或者is not null

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们