LeetCode:620.有趣的电影
题目
某城市开了一家新的电影院,吸引了很多人过来看电影。该电影院特别注意用户体验,专门有个 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 |
+---------+-----------+--------------+-----------+
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/not-boring-movies
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
解答
第一次尝试
---- 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
使用mod()函数,通过mod(id, 2) = 1来确定奇数。
---- MySQL ----
select *
from cinema
where mod(id, 2) = 1
and description != 'boring'
order by rating desc; ---- 99ms
也可以通过位判断的方法
---- MySQL ----
select *
from cinema
where id & 1
and description <> 'boring'
order by rating desc; ---- 102ms
思考
oracle中用mod(a, b)函数进行模运算。
MySQL中可以使用 id % 2 = 1的普通操作,还有按位与 id & 1这种神操作。
LeetCode:620.有趣的电影的更多相关文章
- LeetCode 620. Not Boring Movies (有趣的电影)
题目标签: 题目给了我们一个 cinema 表格, 让我们找出 不无聊的电影,并且id 是奇数的,降序排列. 比较直接简单的,具体看code. Java Solution: Runtime: 149 ...
- leetcode 620. Not Boring Movies 用where语句判断
https://leetcode.com/problems/not-boring-movies/description/ 不管题目简不简单,现在先熟悉语法. 直接用where语句判断即可,判断奇偶可以 ...
- LeetCode - 620. Not Boring Movies
X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a ...
- [LeetCode] 620. Not Boring Movies_Easy tag: SQL
X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a ...
- LeetCode: 620 Not Boring Movies(easy)
题目: X city opened a new cinema, many people would like to go to this cinema. The cinema also gives o ...
- 【MySQL 基础】MySQ LeetCode
MySQL LeetCode 175. 组合两个表 题目描述 表1: Person +-------------+---------+ | 列名 | 类型 | +-------------+----- ...
- [LeetCode] All questions numbers conclusion 所有题目题号
Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...
- 2019年9月Leetcode每日训练日志
2019-09-16 #1171 从链表中删去总和值为零的连续节点 #1170 比较字符串最小字母出现频次 #1169 查询无效交易 #226 翻转二叉树 2019-09-15 #1190 反转每对括 ...
- ➡️➡️➡️leetcode 需要每天打卡,养成习惯
目录 待完成的 完成的 0204 0203 以前 java 的 ! 的操作 不像 c 那样自由,!不要使用在int 变量上 c ^ 是异或操作 体会:c中,malloc 后的新建的数组,默认不是0(j ...
随机推荐
- 为macos开启外接显示器hdpi分辨率
安装了Switch RES,但是缺少当前显示器合适的HDPI分辨率的时候,可以参考这里,自动生成合适的配置文件. https://comsysto.github.io/Display-Override ...
- easyUI之Layout(布局)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- RabbitMQ学习之:(七)Fanout Exchange (转贴+我的评论)
From:http://lostechies.com/derekgreer/2012/05/16/rabbitmq-for-windows-fanout-exchanges/ PunCha: Ther ...
- 转 CentOS 7 环境下安装Maven
下载安装文件 wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3 ...
- Linux 查看Tomcat版本信息
Linux 查看Tomcat版本信息 如果我们想运行在 Linux 下的 Tomcat 版本信息,只需要在 Tomcat 的 bin/ 目录下,运行 version.sh 脚本即可. 1.使用如下命令 ...
- 通过Xshell 执行压缩.zip文件出现unzip: command not found错误的解决办法
利用unzip命令解压缩的时候,出现 -bash: unzip: command not found 的错误. unzip——命令没有找到,其原因肯定是没有安装unzip. 利用一句命令就可以解决了. ...
- 使用throw和throws 引发异常
1.throw 用在方法内抛出异常,通常可以自行使用try catch进行异常处理 如果不自行处理的话,需要在方法上使用throws抛出异常 public static void testAge(){ ...
- PI膜热作用机理
一.热分析法: 二.研究成果 1.PI膜热老化机理 实验条件:8根500w的碘钨灯加热,200倍光学显微镜观察,PI膜的技术指标 实验概述:本研究分别以150 ℃ , 175 ℃ , 200 ℃ , ...
- Linux正则表达式结合三剑客企业级实战
1.取系统ip 解答: 1)ifconfig ens33 |sed -n '2p'|sed "s#inet##g"|sed 's#n.*$##g' 2)ifconfig ens3 ...
- web应用安全
一.三种坏人与servlet安全 网络攻击者 对应的servlet安全规范 假冒者 认证 非法升级者 授权 窃听者 机密性 数据完整性 认证可以防止“假冒者”攻击,授权可以防止“非法升级者”攻击, ...