考虑以下 Postgresql 数据库表:
id | book_id | author_id
----------------------------
1 | 17 | 10
2 | 18 | 10
3 | 19 | 10
4 | 22 | 10
我想在 book_id 的表中插入新的 author_id 值,其中 author_id=10。例如,生成的表格将类似于以下内容...
id | book_id | author_id
----------------------------
1 | 17 | 10
2 | 18 | 10
3 | 19 | 10
4 | 22 | 10
5 | 17 | 11
6 | 18 | 11
7 | 19 | 11
8 | 22 | 11
如果不为每个 book_id 编写单独的插入语句,是否可以编写一个模拟相同行为的插入语句?
最佳答案
试试这个
Insert into table(book_id,author_id)
(
Select table.book_id,11 FROM table
Where author_id=10
)
关于sql - 当其中一个值参数是动态的时,是否可以执行多个插入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24687281/