我有以下简单查询:
SELECT Customer_FirstName, CONCAT('*', Customer_Email, '*')
from Customers;
它将显示如下内容:
John *<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="553f3a3b153238343c397b363a38" rel="noreferrer noopener nofollow">[email protected]</a>*
Tash **
Luis **
正如您所看到的,当表中没有电子邮件地址时,它只显示“**”,这看起来很奇怪。我想显示类似的内容:
John *<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="09636667496e64686065276a6664" rel="noreferrer noopener nofollow">[email protected]</a>*
Tash
Luis
如何省略整个“* email *”?如果我不打印星号,那么我可以简单地使用 IFNULL(Customers_Email, '') 之类的东西
问题是我需要显示星号。
最佳答案
您可以使用CASE WHEN
表达式
SELECT Customer_FirstName, case when Customer_Email is not null then CONCAT('*', Customer_Email, '*') end
from Customers;
关于MySQL:如果字段为空,则不显示特定数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54747526/