MySQL select where column is not empty

后端 未结 13 2141
深忆病人
深忆病人 2020-11-30 18:18

In MySQL, can I select columns only where something exists?

For example, I have the following query:

select phone, phone2
from jewishyellow.users
wh         


        
13条回答
  •  情歌与酒
    2020-11-30 18:35

    We can use CASE for setting blank value to some char or String. I am using NA as Default string.

    SELECT phone,   
    CASE WHEN phone2 = '' THEN 'NA' END AS phone2 ELSE ISNULL(phone2,0) 
    FROM jewishyellow.users  WHERE phone LIKE '813%'
    

提交回复
热议问题