分组拼接GROUP_CONCAT(expr)
- group_concat函数
- 实现分组查询之后的数据进行合并,并返回一个字符串结果。
- 用于将多个字符串拼接成一个字符串。
- MySql默认的最大拼接长度为1024个字节
应用场景:按照产品编码分组,获取生效策略
SELECT
product_no,
group_concat(
CONCAT(
"[",(
CASE
WHEN strategy_type = 1 THEN
"通信计划"
WHEN strategy_type = 2 THEN
"资费计划"
WHEN strategy_type = 3 THEN
"PCRF策略"
WHEN strategy_type = 4 THEN
"收费事件"
WHEN strategy_type = 6 THEN
"Panabit策略"
WHEN strategy_type = 7 THEN
"捷德策略" ELSE ""
END
),
"]",
strategy_id
) SEPARATOR ','
) AS strategy_info
FROM
t_data_product_strategy
WHERE
type = 1
GROUP BY
product_no