gpt4 book ai didi

mysql - 如何编写一个 SQL 补丁,从表 A 中获取值并将其作为行插入到表 B 中?

转载 作者:太空宇宙 更新时间:2023-11-03 10:37:21 25 4
gpt4 key购买 nike

我只需要获取 photoProcess 表中具有 storyId 值(非 0 或 null)的每一行,然后将一个条目插入到名为 photoProcessStory 的新表中。

photoProcess 表中的行示例:

+----------------+----------+----------+
| processId | storyId | rating |
+----------------+----------+----------+
| 111111111 | 322 | 1 |
| 111111112 | 333 | 1 |
| 111111113 | 0 | 1 |
+----------------+----------+----------+

最终生成的 photoProcessStory 表如下所示:

+-----+----------------+-------------------+
| id | processId | storyId |
+-----|----------------+-------------------+
| 1 | 111111111 | 322 |
| 2 | 111111112 | 333 |
+-----+----------------+-------------------+

如有任何帮助,我们将不胜感激。我有连接表和将值插入列的经验,但我不熟悉如何在这样的补丁中插入行。

最佳答案

insert into photoProcessStory (processId, storyId)
select processId, storyId
from photoProcess
where storyId <> 0 and storyId is not null

关于mysql - 如何编写一个 SQL 补丁,从表 A 中获取值并将其作为行插入到表 B 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45696215/

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