我需要在数据库中创建一个禁令列表。在您问之前,不,这实际上不是书籍,禁止书籍是愚蠢的。为此,我要根据表中已有的条件进行选择,然后直接将其插入Bans表中。问题是,出于禁令的原因,我想包括一个手动字符串。我在下面提供了一些示例数据以及当前使用的SQL。
323,2013-06-03 00:00:00,0.0
323,2013-06-03 01:00:00,1.0
323,2013-06-03 02:00:00,1.5
323,2013-06-03 03:00:00,1.5
323,2013-06-03 04:00:00,0.0
323,2013-06-03 05:00:00,0.5
323,2013-06-03 06:00:00,0.0
323,2013-06-03 07:00:00,3.5
323,2013-06-03 08:00:00,0.5
ID | Author | Title
1 | Mark Twain | Huckleberry Fin
2 | Stephen King | IT
3 | Mark Twain | Tom Sawyer
4 | Stephen King | Carrie
5 | William Shakespeare| Hamlet
6 | Stephen King | The Stand
7 | Ernest Hemingway | The Old Man and the Sea
8 | JK Rowling | Harry Potter
9 | Ernest Hemingway | For Whom the Bell Tolls
10 | William Shakespeare| Othello
11 | Ernest Hemingway | A Farewell to Arms
12 | William Shakespeare| Richard III
13 | JK Rowling | Fantastic Beasts and where to find them
在其中作者=“斯蒂芬·金”的书籍中插入或忽略所有选择ID
此查询会将Stephan Kings图书的所有ID放入bans表中。但是,我希望能够指出被禁止的原因。
ID | Reason
8 | Magic & Stuff
13 | Magic & Stuff
我想做的是查询一个可以让我给出原因的查询。所以我最终选择了这个
ID | Reason
8 | Magic & Stuff
13 | Magic & Stuff
2 |
4 |
6 |
这怎么办?
答案 0 :(得分:0)
INSERT OR IGNORE INTO Bans
SELECT ID, "Too Scary For Kids" FROM Books WHERE Author = "Stephen King"