gpt4 book ai didi

mysql 从字符串列表中获取不同的标记

转载 作者:可可西里 更新时间:2023-11-01 07:59:32 26 4
gpt4 key购买 nike

我在 mysql 中有一个查询,group concats 记录并给出一个具有冗余标记的值。以下是查询的输出:

Problem Area->ACC-HO->ACC-HO->Credit Note (C/N)->Problem description ->Problem description 

但是我想要这个字符串的不同标记如下

Problem Area->ACC-HO->Credit Note (C/N)->Problem description 

有没有办法在 sql SELECT 查询本身中执行此操作?

编辑这是 schema and query以下是我的查询:

SELECT 
t2.transaction_id AS transaction_id,
GROUP_CONCAT(
CONCAT(
t1.display_text,
'->',
(CASE (NOT EXISTS (SELECT 1 FROM mst_node a WHERE a.parent_node_id = t1.node_id))
WHEN 1 THEN t1.display_text ELSE
(SELECT b.display_text AS DISPLAY FROM mst_node b
WHERE parent_node_id = t2.node_id AND b.display_seq = t2.entered_value)
END)
)
ORDER BY t2.logtime_stamp SEPARATOR '->'
) AS display_text
FROM

mst_node t1
JOIN trn_user_log t2
ON t1.app_id = t2.app_id AND t1.node_id = t2.node_id
WHERE (t1.app_id = 105)
AND t1.parent_node_id IS NOT NULL
AND t1.save_as_default IS NULL
GROUP BY transaction_id,
mobile_no
ORDER BY t2.transaction_id DESC,
t2.logtime_stamp,
t2.mobile_no

最佳答案

GROUP CONCAT 中添加 DISTINCT,这样它只会连接唯一值。

SELECT GROUP_CONCAT(DISTINCT colName),....
FROM ...
WHERE ...
GROUP BY ...

SQLFiddle Demo

关于mysql 从字符串列表中获取不同的标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12597934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com