LeetCode:. 620 funny movie

Topic links: https://leetcode-cn.com/problems/not-boring-movies/

topic

A city opened a new cinema, attract a lot of people came to see the movie. The cinema special attention to the user experience, there is a dedicated LED display board to do a movie recommendation, it announced the critics and movie-related described above.

As the director of the movie theater information, you need to write a SQL query to find all the videos described as non-boring (not boring) and id is an odd movie, please arrange results by grade rating.

For example, the following table cinema:

+ --------- + ----------- + ----------- + -------------- +
| the above mentioned id | Movie | the 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 | Card House | Interesting | 9.1 |
+ --------- + ----- + ----------- + -------------- + ------
for the above example, the correct output is:

+---------+-----------+--------------+-----------+
| id | movie | description | rating |
+---------+-----------+--------------+-----------+
| 5 | House card| Interesting| 9.1 |
| 1 | War | great 3D | 8.9 |
+---------+-----------+--------------+-----------+

Source: stay button (LeetCode)
link: https://leetcode-cn.com/problems/not-boring-movies
copyrighted by deduction from all networks. Commercial reprint please contact the authorized official, non-commercial reprint please indicate the source.

answer

First attempt

---- oracle ----
/* Write your PL/SQL query statement below */
select id,
       movie,
       description,
       rating
from cinema
where description <> 'boring'
and mod(id, 2) <> 0
order by rating desc ---- 796ms

Using the mod()function, by mod(id, 2) = 1determining be odd.

---- MySQL ----
select *
from cinema
where mod(id, 2) = 1
and description != 'boring'
order by rating desc;  ---- 99ms

Bit may be determined by the method of

---- MySQL ----
select *
from cinema
where id & 1
and description <> 'boring'
order by rating desc;  ---- 102ms

Think

oracle with mod(a, b)function modulo operation.

MySQL can be used in id % 2 = 1normal operation, as well as bit and id & 1this god operation.

Guess you like

Origin www.cnblogs.com/hider/p/11723667.html