我目前能够使用以下SQL将行插入表中:
INSERT INTO ots (score_id,tab_id) VALUES ((SELECT id FROM score WHERE score_id = 11),(SELECT tab_id FROM tab WHERE layover_state = 7))
INSERT INTO ots (score_id,tab_id) VALUES ((SELECT id FROM score WHERE score_id = 12),(SELECT tab_id FROM tab WHERE layover_state = 7))
INSERT INTO ots (score_id,tab_id) VALUES ((SELECT id FROM score WHERE score_id = 19),(SELECT tab_id FROM tab WHERE layover_state = 9))
INSERT INTO ots (score_id,tab_id) VALUES ((SELECT id FROM score WHERE score_id = 27),(SELECT tab_id FROM tab WHERE layover_state = 10))
INSERT INTO ots (score_id,tab_id) VALUES ((SELECT id FROM score WHERE score_id = 45),(SELECT tab_id FROM tab WHERE layover_state = 10))
INSERT INTO ots (score_id,tab_id) VALUES ((SELECT id FROM score WHERE score_id = 51),(SELECT tab_id FROM tab WHERE layover_state = 10))
INSERT INTO ots (score_id,tab_id) VALUES ((SELECT id FROM score WHERE score_id = 52),(SELECT tab_id FROM tab WHERE layover_state = 11))
上述INSERT INTO
语句可以正常使用。但是,它们看起来非常低效,因为应该有一些方法可以使用列表来捕获我需要指定的所有整数作为嵌套SELECT
语句的一部分。但是,我不确定如何将score_id
放入SQL列表,同时在单独的列表中保留layover_state
的顺序。
问题
有没有办法用一行使用2个SQL列表替换上面的代码行?
其他信息:
我在MySQL Workbench中使用MySQL。