0

我正在创建一个加入 2 个表的视图。我有一个列许可证,其中我已将其分组到带有分隔符的单个单元格中。对于引用表中的相应服务,许可字段可能具有空值。因此,在查看特定代理的许可证列时,它应该显示空值以及分隔符。

例如,代理id = 802,他的服务列与许多服务组合在一起,分隔符看起来像

Mututal Funds||Investments||Life Insurance||Personal Loan
123456       ||NULL       ||34567         ||NUL

其中投资和个人贷款的许可证值为 NULL,但我得到的是123456||34567 ,空值被自动拒绝......但我需要将 Null 包含在结果集中......我的查询是

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER 
VIEW `v_agent_service` AS 
select `a`.`agent_id` AS `agent_id`,
       group_concat(`a`.`license`separator '||') AS `license`,
       group_concat(`s`.`service_name` separator '||') AS  `service_names` 
from 
(`agent_service` `a` left join `service` `s` 
on((`s`.`service_id`  = `a`.`service_id`)))
group by `a`.`agent_id`;
4

1 回答 1

0

您可以使用IFNULL()将空值转换为包含以下内容的字符串'null'

group_concat(IFNULL(`a`.`license`, 'NULL') separator '||') AS `license`,
于 2013-03-12T06:55:40.990 回答