Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何编写一个SQL修补程序,从表a中获取值并在表B中作为行插入?_Mysql_Sql - Fatal编程技术网

Mysql 如何编写一个SQL修补程序,从表a中获取值并在表B中作为行插入?

Mysql 如何编写一个SQL修补程序,从表a中获取值并在表B中作为行插入?,mysql,sql,Mysql,Sql,我只需要获取photoProcess表中具有storyId值(不是0或null)的每一行,然后在名为photoProcessStory的新表中插入一个条目 photoProcess表中的行示例: +----------------+----------+----------+ | processId | storyId | rating | +----------------+----------+----------+ | 111111111 | 322 |

我只需要获取
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;
插入photoProcessStory(processId,storyId)
从photoProcess中选择processId、storyId,其中storyId为0;

您可以使用
插入。。选择
,例如:

INSERT INTO photoProcessStory (processId, storyId)
SELECT processId, storyId FROM photoProcess WHERE storyId <> 0;
插入photoProcessStory(processId,storyId)
从photoProcess中选择processId、storyId,其中storyId为0;

这只是一个
插入。选择

insert into photoProcessStory(processId, storyId)
    select processId, storyId
    from photoProcess
    where storyId <> 0;
插入photoProcessStory(processId,storyId)
选择processId、storyId
从光加工
其中storyid0;

这只是一个
插入。选择

insert into photoProcessStory(processId, storyId)
    select processId, storyId
    from photoProcess
    where storyId <> 0;
插入photoProcessStory(processId,storyId)
选择processId、storyId
从光加工
其中storyid0;
插入photoProcessStory(processId,storyId)
选择processId、storyId
从光加工
其中,storyId 0和storyId不为null
插入photoProcessStory(processId,storyId)
选择processId、storyId
从光加工
其中,storyId 0和storyId不为null

非常感谢您。唯一的问题是它应该是photoProcessStory,而不是photoProcessHistory。@jmchauv请勾选这个作为正确答案,如果事实是这样的话。@khaledOuertani我会尽快告诉我。您必须等待一定时间才能标记它。非常感谢。唯一的问题是它应该是photoProcessStory,而不是photoProcessHistory。@jmchauv请勾选这个作为正确答案,如果事实是这样的话。@khaledOuertani我会尽快告诉我。您必须等待一定时间才能标记它。