我在postgresql上有这个查询
SELECT
unnest(array[ sale_contact_name, purchase_contact_name, admin_contact_name]) AS name ,
unnest(array[ sale_contact_mobile , purchase_contact_mobile , admin_contact_mobile ]) AS mobile ,
unnest(array[ sale_contact_phone, purchase_contact_phone, admin_contact_phone]) AS phone
from company_t
where companyCode = 'anything' ;
如果没有数据,我会得到空字符串。 我不想得到这些空字符串,我怎么能这样做
答案 0 :(得分:0)
您可以使用CASE
语句来处理空字符串:
SELECT CASE WHEN t.name = '' THEN 'Alt name' ELSE t.name END,
CASE WHEN t.mobile = '' THEN 'Alt mobile' ELSE t.mobile END,
CASE WHEN t.phone = '' THEN 'Alt phone' ELSE t.phone END
FROM
(
SELECT unnest(array[ sale_contact_name, purchase_contact_name, admin_contact_name]) AS name,
unnest(array[ sale_contact_mobile, purchase_contact_mobile , admin_contact_mobile ]) AS mobile,
unnest(array[ sale_contact_phone, purchase_contact_phone, admin_contact_phone]) AS phone
FROM company_t
WHERE companyCode = 'anything'
) t