此问题已在此处有答案:
To INSERT values from CTE result(1个答案)
2天前关闭。
我正在尝试向外键插入标识。下面是我的代码:
WITH p AS (SELECT id FROM tbl_place WHERE txt_place = "Place 1")
INSERT INTO tbl_sheet(txt_rep_no, txt_song_name, id_place, id_source_by, id_compiled_by, id_notation_by, id_type, blob_sheet1)
VALUES("1", "Song Name 1", p.id, 1, 1, 1, "", "")
这给了我错误
没有这样的栏目p.id
如何选择并插入多个外键?
编辑:我尝试添加“with”句子,但出现错误:“WITH”:语法错误
INSERT INTO tbl_sheet(txt_rep_no, txt_song_name, id_place, id_source_by, id_compiled_by, id_notation_by, id_type, blob_sheet1)
WITH p AS (SELECT id FROM tbl_place WHERE txt_place = "Place 1")
WITH s AS (SELECT id FROM tbl_person WHERE txt_person = "Person 1")
WITH c AS (SELECT id FROM tbl_person WHERE txt_person = "Person 1")
WITH n AS (SELECT id FROM tbl_person WHERE txt_person = "Person 1")
SELECT "1", "Song 1", p.id, s.id, c.id, n.id, 1, ""
FROM p
1条答案
按热度按时间6qqygrtg1#
因为你用错了顺序:
INSERT INTO
WITH
子句SELECT
from table(-s)fromWITH
子句