sqlite 插入多个带别名的外键[重复]

fdx2calv  于 2023-04-12  发布在  SQLite
关注(0)|答案(1)|浏览(210)

此问题已在此处有答案

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
6qqygrtg

6qqygrtg1#

因为你用错了顺序:

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")
SELECT "1", "Song Name 1", p.id, 1, 1, 1, "", ""
FROM p
  1. INSERT INTO
  2. WITH子句
  3. SELECT from table(-s)from WITH子句

相关问题