3358. 评分为 NULL 的图书

力扣题目跳转(3358. 评分为 NULL 的图书 - 力扣(LeetCode)

表:books

+----------------+---------+
| Column Name    | Type    |
+----------------+---------+
| book_id        | int     |
| title          | varchar |
| author         | varchar |
| published_year | int     |
| rating         | decimal |
+----------------+---------+
book_id 是这张表的唯一主键。
这张表的每一行包含关于一本书的唯一 ID,题目,作者,出版年份以及评分的信息。
评分可能为 NULL,表示这本书还没有被评分。

 题目要求:

编写一个解决方案来找到所有还没有被评分的图书。(即评分为 NULL

返回结果表以 book_id 升序 排序。

结果格式如下所示。

示例:

输入:

books 表:

+---------+------------------------+------------------+----------------+--------+
| book_id | title                  | author           | published_year | rating |
+---------+------------------------+------------------+----------------+--------+
| 1       | The Great Gatsby       | F. Scott         | 1925           | 4.5    |
| 2       | To Kill a Mockingbird  | Harper Lee       | 1960           | NULL   |
| 3       | Pride and Prejudice    | Jane Austen      | 1813           | 4.8    |
| 4       | The Catcher in the Rye | J.D. Salinger    | 1951           | NULL   |
| 5       | Animal Farm            | George Orwell    | 1945           | 4.2    |
| 6       | Lord of the Flies      | William Golding  | 1954           | NULL   |
+---------+------------------------+------------------+----------------+--------+

输出:

+---------+------------------------+------------------+----------------+
| book_id | title                  | author           | published_year |
+---------+------------------------+------------------+----------------+
| 2       | To Kill a Mockingbird  | Harper Lee       | 1960           |
| 4       | The Catcher in the Rye | J.D. Salinger    | 1951           |
| 6       | Lord of the Flies      | William Golding  | 1954           |
+---------+------------------------+------------------+----------------+

解释:

  • book_id 为 2,4,6 的书评分为 NULL。
  • 这些书被包含在结果表中。
  • 其它书(book_id 为 1,3,5)有评分并且没有被包含。

结果以 book_id 升序排序。

case 1 的建表语句。

Create table books (
    book_id int,
    title varchar(255),
    author varchar(100),
    published_year int,
    rating decimal(3,1)
)
Truncate table books
insert into books (book_id, title, author, published_year, rating) values ('1', 'The Great Gatsby', 'F. Scott', '1925', '4.5')
insert into books (book_id, title, author, published_year, rating) values ('2', 'To Kill a Mockingbird', 'Harper Lee', '1960', NULL)
insert into books (book_id, title, author, published_year, rating) values ('3', 'Pride and Prejudice', 'Jane Austen', '1813', '4.8')
insert into books (book_id, title, author, published_year, rating) values ('4', 'The Catcher in the Rye', 'J.D. Salinger', '1951', NULL)
insert into books (book_id, title, author, published_year, rating) values ('5', 'Animal Farm', 'George Orwell', '1945', '4.2')
insert into books (book_id, title, author, published_year, rating) values ('6', 'Lord of the Flies', 'William Golding', '1954', NULL)

一     按照要求填选字段使用条件筛选和排序即可。

select book_id, title, author, published_year from books where rating is null order by book_id;

输出如下

以上就是全部答案,如果对你有帮助请点个赞,谢谢。

来源:力扣(leecode

著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

 转载请注明出处:

3358. 评分为 NULL 的图书-优快云博客我会尽快把力扣上的所有数据库题目发出来。这张表的每一行包含关于一本书的唯一 ID,题目,作者,出版年份以及评分的信息。著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。编写一个解决方案来找到所有还没有被评分的图书。评分可能为 NULL,表示这本书还没有被评分。book_id 是这张表的唯一主键。结果以 book_id 升序排序。https://blog.youkuaiyun.com/CYJ1844/article/details/144446218

我会尽快把力扣上的所有数据库题目发出来。感兴趣的可以点个赞与关注。每天不定时跟新。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值