mysql的case when字段為空,null的問題
更新時間:2022年12月13日 09:10:26 作者:我有一個魔盒
這篇文章主要介紹了mysql的case when字段為空,null的問題。具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
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 '暫無數(shù)據(jù)' end) as deviceTag,
(case when cdi.DEVICE_CODE is not null then cdi.DEVICE_CODE else '暫無數(shù)據(jù)' end) as deviceCode,
(case when sc.full_name is not null then sc.full_name else '暫無數(shù)據(jù)' end) as deviceVendor,
(case when ct.CLASS_NAME is not null then ct.CLASS_NAME else '暫無數(shù)據(jù)' end) as deviceTypeNameB,
(case when cdi.DEVICE_PORT is not null then cdi.DEVICE_PORT else '暫無數(shù)據(jù)' end) as devicePort,
(case when cdi.CREATE_TIME is not null then cdi.CREATE_TIME else '暫無數(shù)據(jù)' 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
總結
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
使用Mycat-eye管理Mycat數(shù)據(jù)庫服務的操作
MyCat是一個開源的分布式數(shù)據(jù)庫系統(tǒng),是一個實現(xiàn)了MySQL協(xié)議的服務器,前端用戶可以把它看作是一個數(shù)據(jù)庫代理,用MySQL客戶端工具和命令行訪問,本文給大家介紹了使用Mycat-eye管理Mycat數(shù)據(jù)庫服務的操作,需要的朋友可以參考下2024-04-04
MySQL數(shù)據(jù)庫實驗之?觸發(fā)器和存儲過程
這篇文章主要介紹了MySQL數(shù)據(jù)庫實驗之?觸發(fā)器和存儲過程,通過掌握某主流DBMS支持的SQL編程語言和編程規(guī)范,規(guī)范設計存儲過程展開詳細介紹,感興趣的朋友可以參考一下2022-06-06

