gpt4 book ai didi

mysql - 使用另一个查询的结果将多行插入数据库

转载 作者:行者123 更新时间:2023-11-29 11:11:50 27 4
gpt4 key购买 nike

我想使用另一个查询的输出将多行插入到我的表中。

我的插入语句如下所示:

INSERT INTO group_messages (group_message_text,group_message_group_id,group_message_user_id)
VALUES ('Rounded ended! Hit the standings button in the top right corner to check your score.','$group_id','0')

这里$group_id将需要填充任意数量的group_ids从此查询返回:

SELECT group_id
FROM groups

第二个查询现在返回 3 group_ids: 1, 2, 3

这应该导致类似的结果:

INSERT INTO group_messages (group_message_text,group_message_group_id,group_message_user_id)
VALUES ('Rounded ended! Hit the standings button in the top right corner to check your score.','1','0'), ('Rounded ended! Hit the standings button in the top right corner to check your score.','2','0'), ('Rounded ended! Hit the standings button in the top right corner to check your score.','3','0')

最佳答案

试试这个

INSERT INTO group_messages 
(group_message_text,group_message_group_id,group_message_user_id)
select "Rounded ended! Hit the standings button in the top right corner to
check your score.",group_id,0 FROM groups

关于mysql - 使用另一个查询的结果将多行插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40435380/

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