继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

(LeetCode620:有趣的电影)

青春有我
关注TA
已关注
手记 1072
粉丝 205
获赞 1007

Solution:
某城市开了一家新的电影院,吸引了很多人过来看电影。该电影院特别注意用户体验,专门有个 LED显示板做电影推荐,上面公布着影评和相关电影描述。
作为该电影院的信息部主管,您需要编写一个 SQL查询,找出所有影片描述为非 boring (不无聊) 的并且 id 为奇数 的影片,结果请按等级 rating 排列。

例如,下表 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     |+---------+-----------+--------------+-----------+
+---------+-----------+--------------+-----------+|   id    | movie     |  description |  rating   |
+---------+-----------+--------------+-----------+
|   5     | House card|   Interesting|   9.1     ||   1     | War       |   great 3D   |   8.9     |
+---------+-----------+--------------+-----------+

Solution:

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

两条sql 可是实现相同的结果。

友情提示:
mysql   != 和 <>   的查询结果不包含 null 的字段,所以设置属性最好要求属性 not null。



作者:lconcise
链接:https://www.jianshu.com/p/095e319cdda3


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP