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 ...
随机推荐
- usage memcache in linux
set和add的区别 set可以重写存在的键值对, 也可以添加新的/ 而add不行, 如果存在已有的键名, 则add不会做更新该键值对, 不做任何事, 就是一次无效操作, 也就是, add可以防止重写 ...
- Ubuntu 安装 docker,并上传到dockerhub
一.安装Docker apt-get -y install docker.io 链接: ln -sf /usr/bin/docker.io /usr/local/bin/docker 检查docker ...
- RTSP协议-中文定义
RTSP协议-中文定义 转自:http://blog.csdn.net/arau_sh/article/details/2982914 E-mail:bryanj@163.com 译者: Bryan. ...
- k8s-高可用多主master配置
准备主机 centos7镜像 node1: 192.168.0.101 node2: 192.168.0.102 node3: 192.168.0.103 vip: 192.168.0.104 配置s ...
- React Native小知识点记录
1>查看 RN 的所有历史版本: npm view react-native versions -json 2>查看 RN 的当前版本: npm view react-native ver ...
- sql server 本机编译存储过程(内存优化表) 绕过不支持FULL OUTER JOIN 的限制的方法
将FULL OUTER JOIN 转成left join,right join 和 union select * from A ID NAME4 Spaghetti1 Pirate2 Monkey3 ...
- 在centos卸载mysql
1 rpm -qa|grep mysql 查看安装了哪些mysql和lib…… 1 yum remove mysql mysql-server mysql-libs compat-mysql51 删除 ...
- Docker Swarm常用命令
#查看集群节点 docker node ls #创建nginx服务 #docker pull hub.test.com:5000/almi/nginx:0.1 #下载私有仓库镜像 docker ser ...
- 快速搭建WordPress博客
博主在看了朋友的博客后 决定也搭建一个wordPress 博客 思路 1.购买服务器 2.Cenots环境配置 3.安装wordpress 工具 推荐使用 Xshell 6,当然也可以用其他 服务器推 ...
- javaweb期末项目-stage1-part2-UML设计
UML设计.rar-下载 说明:解压密码为袁老师全名拼音(小写) 相关链接: 项目结构:https://www.cnblogs.com/formyfish/p/10828672.html 需求分析:h ...