将 NULL 替换为串联函数中的自定义文本 SQL

Replace NULL with custom text inside the concatenation function SQL

我想拼接属于同一个id的输出,所以我用了下面的函数,但是我也想用自定义文本替换空值,请问应该怎么做才对?

GROUP_CONCAT(IFNULL(ps_state.name, 'No-State') SEPARATOR ', ')

所有代码(如果需要):

SELECT DISTINCT ps_customer.id_customer AS CustomersId, ps_customer.email AS CustomersName, GROUP_CONCAT(IFNULL(ps_state.name, 'No') SEPARATOR ', ') AS StatesName, 
GROUP_CONCAT(ps_country_lang.name SEPARATOR ', ') AS CountryName 
FROM ps_customer
INNER JOIN ps_address ON ps_customer.id_customer=ps_address.id_customer
LEFT JOIN ps_state ON ps_state.id_state=ps_address.id_state
INNER JOIN ps_country_lang ON ps_country_lang.id_country=ps_address.id_country
WHERE ps_country_lang.id_lang=1
GROUP BY ps_customer.id_customer, ps_state.name

您的代码基本上看起来是正确的,但我会使用 coalesce():

GROUP_CONCAT(coalesce(ps_state.name, 'No-State') SEPARATOR ', ')

如果有您想要或期望的订单,您可能还想在 GROUP_CONCAT() 内订购。