试图找到名称为 Python psql 的所有书籍

Trying to find all books with the name Python psql

你好我正在为我的软件工程做 psql 数据库的作业 class 我必须做的问题之一是“找到所有包含 Python 的书”所以我尝试使用 WHERE 语法,但它会给我 0 行没有标题中包含单词 Python 的书籍,但书籍中显然有 table 谁能帮我解决这个问题?

booktown=# SELECT books.title FROM books WHERE title NOT IN ('Python');

            title
-----------------------------
 The Shining
 Dune
 2001: A Space Odyssey
 The Cat in the Hat
 Bartholomew and the Oobleck
 Franklin in the Dark
 Goodnight Moon
 Little Women
 The Velveteen Rabbit
 Dynamic Anatomy
 The Tell-Tale Heart
 Programming Python
 Learning Python
 Perl Cookbook
 Practical PostgreSQL
(15 rows)

booktown=# SELECT books.title FROM books WHERE title IN ('Python');
 title
-------
(0 rows)

booktown=# SELECT books.title FROM books WHERE title LIKE 'Python';
 title
-------
(0 rows)

booktown=# SELECT books.title FROM books WHERE title LIKE 'Python';

您应该使用 Postgresql 的 LIKE 运算符进行模式匹配。您查询的方式将进行精确匹配。请参阅 https://www.postgresqltutorial.com/postgresql-like/

中的示例

title IN ('Python') 查找标题在列表中的所有书籍。该列表仅包含一个条目 'Python'。没有标题为 'Python'.

的书

title LIKE 'Python' 查找标题与模式 'Python' 匹配的所有书籍。由于模式中没有通配符(即 %_),这会查找完全匹配。同样,没有名为 'Python'.

的书

您希望所有标题都符合以下模式:“零个或多个我们不关心的字符,然后是单词 Python,然后是零个或多个我们不感兴趣的字符”。

也就是title LIKE '%Python%'.