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我会尽快告诉我。您必须等待一定时间才能标记它。