我有以下简单查询:
SELECT Customer_FirstName, CONCAT('*', Customer_Email, '*')
from Customers;
它将显示如下内容:
John *jon@gmail.com*
Tash **
Luis **
如您所见,当表中没有电子邮件地址时,它仅显示“ **”,看起来很奇怪。我想显示以下内容:
John *jon@gmail.com*
Tash
Luis
如何省略整个“ *电子邮件*”?如果我不打印星号,那么我可以简单地使用IFNULL(Customers_Email,'')
问题是我需要显示星号。
答案 0 :(得分:2)
您可以使用CASE WHEN
表达式
SELECT Customer_FirstName, case when Customer_Email is not null then CONCAT('*', Customer_Email, '*') end
from Customers;
答案 1 :(得分:2)
使用此:
SELECT Customer_FirstName, IF(Customer_Email IS NULL OR Customer_Email = '','',CONCAT('*',Customer_Email, '*')) as Customer_Email
from Customers;