★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-wcaostsv-me.html
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★html
SQL架構git
1 Create table If Not Exists cinema (id int, movie varchar(255), description varchar(255), rating float(2, 1)) 2 Truncate table cinema 3 insert into cinema (id, movie, description, rating) values ('1', 'War', 'great 3D', '8.9') 4 insert into cinema (id, movie, description, rating) values ('2', 'Science', 'fiction', '8.5') 5 insert into cinema (id, movie, description, rating) values ('3', 'irish', 'boring', '6.2') 6 insert into cinema (id, movie, description, rating) values ('4', 'Ice song', 'Fantacy', '8.6') 7 insert into cinema (id, movie, description, rating) values ('5', 'House card', 'Interesting', '9.1')
X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a poster indicating the movies’ ratings and descriptions.github
Please write a SQL query to output movies with an odd numbered ID and a description that is not 'boring'. Order the result by rating. sql
For example, table cinema
:微信
+---------+-----------+--------------+-----------+ | 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 | +---------+-----------+--------------+-----------+
For the example above, the output should be:架構
+---------+-----------+--------------+-----------+ | id | movie | description | rating | +---------+-----------+--------------+-----------+ | 5 | House card| Interesting| 9.1 | | 1 | War | great 3D | 8.9 | +---------+-----------+--------------+-----------+
某城市開了一家新的電影院,吸引了不少人過來看電影。該電影院特別注意用戶體驗,專門有個 LED顯示板作電影推薦,上面公佈着影評和相關電影描述。post
做爲該電影院的信息部主管,您須要編寫一個 SQL查詢,找出全部影片描述爲非 boring
(不無聊) 的而且 id 爲奇數 的影片,結果請按等級 rating
排列。 this
例如,下表 cinema
:spa
+---------+-----------+--------------+-----------+ | 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 | +---------+-----------+--------------+-----------+
對於上面的例子,則正確的輸出是爲:rest
+---------+-----------+--------------+-----------+ | id | movie | description | rating | +---------+-----------+--------------+-----------+ | 5 | House card| Interesting| 9.1 | | 1 | War | great 3D | 8.9 | +---------+-----------+--------------+-----------+
108ms
1 # Write your MySQL query statement below 2 select id, movie, description, rating 3 from cinema 4 where mod(id,2) = 1 AND description <> "boring" 5 order by rating desc
109ms
1 # Write your MySQL query statement below 2 select * from cinema where description != 'boring' and id % 2 = 1 order by rating desc
110ms
1 # Write your MySQL query statement below 2 select a.* from cinema as a where mod(a.id,2)=1 and a.description != 'boring' order by rating desc;
111ms
1 # Write your MySQL query statement below 2 select * 3 from cinema 4 where not description = "boring" and mod(id, 2) = 1 5 order by rating desc
115ms
1 # Write your MySQL query statement below 2 select * from cinema 3 where id%2 <> 0 4 and description not like "%boring%" 5 order by rating desc