gpt4 book ai didi

sql - 选择更多行作为列

转载 作者:可可西里 更新时间:2023-11-01 08:22:42 24 4
gpt4 key购买 nike

我有一个 MySQL 问题

我想将下一个查询的结果放入一个 var 中并用它来更新到触发器中我正在尝试以逗号分隔的名称

查询返回不止一行

SELECT t.naam
FROM trefwoorden t
INNER JOIN organisaties_has_trefwoorden AS o ON (t.id_trefwoorden = o.id_trefwoorden)
WHERE o.id_organisaties = NEW.id_organisaties;

这是触发器

CREATE TRIGGER updCheck_After AFTER
UPDATE ON organisaties_has_trefwoorden
FOR EACH row

UPDATE organisaties o
SET o.trefwoorden_flat =
(
SELECT t.naam
FROM trefwoorden t
INNER JOIN organisaties_has_trefwoorden AS o ON (t.id_trefwoorden = o.id_trefwoorden)
WHERE o.id_organisaties = NEW.id_organisaties;
)
WHERE o.id_organisaties = NEW.id_organisaties

问题是可以选择更多行作为 1 列逗号分隔还是有其他解决方案?

有人建议吗?

最佳答案

UPDATE  organisaties o
SET o.trefwoorden_flat =
(
SELECT GROUP_CONCAT(t.naam SEPARATOR ',')
FROM trefwoorden t
INNER JOIN
organisaties_has_trefwoorden AS o
ON t.id_trefwoorden = o.id_trefwoorden
WHERE o.id_organisaties = NEW.id_organisaties
)
WHERE o.id_organisaties = NEW.id_organisaties

关于sql - 选择更多行作为列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2788290/

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