返回介绍

solution / 0600-0699 / 0620.Not Boring Movies / README_EN

发布于 2024-06-17 01:03:36 字数 2596 浏览 0 评论 0 收藏 0

620. Not Boring Movies

中文文档

Description

Table: Cinema

+----------------+----------+
| Column Name  | Type   |
+----------------+----------+
| id       | int    |
| movie      | varchar  |
| description  | varchar  |
| rating     | float  |
+----------------+----------+
id is the primary key (column with unique values) for this table.
Each row contains information about the name of a movie, its genre, and its rating.
rating is a 2 decimal places float in the range [0, 10]

 

Write a solution to report the movies with an odd-numbered ID and a description that is not "boring".

Return the result table ordered by rating in descending order.

The result format is in the following example.

 

Example 1:

Input: 
Cinema table:
+----+------------+-------------+--------+
| id | movie    | description | rating |
+----+------------+-------------+--------+
| 1  | War    | great 3D  | 8.9  |
| 2  | Science  | fiction   | 8.5  |
| 3  | irish    | boring    | 6.2  |
| 4  | Ice song   | Fantacy   | 8.6  |
| 5  | House card | Interesting | 9.1  |
+----+------------+-------------+--------+
Output: 
+----+------------+-------------+--------+
| id | movie    | description | rating |
+----+------------+-------------+--------+
| 5  | House card | Interesting | 9.1  |
| 1  | War    | great 3D  | 8.9  |
+----+------------+-------------+--------+
Explanation: 
We have three movies with odd-numbered IDs: 1, 3, and 5. The movie with ID = 3 is boring so we do not include it in the answer.

Solutions

Solution 1: Conditional Filtering + Sorting

We can use the WHERE clause to filter out the records where description is not boring and id is odd, and then use the ORDER BY clause to sort the result in descending order by rating.

# Write your MySQL query statement below
SELECT *
FROM Cinema
WHERE description != 'boring' AND id & 1 = 1
ORDER BY 4 DESC;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文