mysql的case when字段为空,null的问题
吾爱主题
阅读:150
2022-12-15 16:53:00
评论:0
mysql的case when字段为空,null
name字段为null时替换为 ‘该字段为空’
?1 2 3 4 5 6 7 | SELECT CASE WHEN name is null THEN '该字段为空' ELSE name END as name ,email_id FROM mysql_table_name |
case when 判断null(已测试)
?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/weixin_40277264/article/details/108664454
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。