题目链接:https://leetcode-cn.com/problems/not-boring-movies/

题目

某城市开了一家新的电影院,吸引了很多人过来看电影。该电影院特别注意用户体验,专门有个 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.有趣的电影的更多相关文章

  1. LeetCode 620. Not Boring Movies (有趣的电影)

    题目标签: 题目给了我们一个 cinema 表格, 让我们找出 不无聊的电影,并且id 是奇数的,降序排列. 比较直接简单的,具体看code. Java Solution: Runtime:  149 ...

  2. leetcode 620. Not Boring Movies 用where语句判断

    https://leetcode.com/problems/not-boring-movies/description/ 不管题目简不简单,现在先熟悉语法. 直接用where语句判断即可,判断奇偶可以 ...

  3. 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 ...

  4. [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 ...

  5. 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 ...

  6. 【MySQL 基础】MySQ LeetCode

    MySQL LeetCode 175. 组合两个表 题目描述 表1: Person +-------------+---------+ | 列名 | 类型 | +-------------+----- ...

  7. [LeetCode] All questions numbers conclusion 所有题目题号

    Note: 后面数字n表明刷的第n + 1遍, 如果题目有**, 表明有待总结 Conclusion questions: [LeetCode] questions conclustion_BFS, ...

  8. 2019年9月Leetcode每日训练日志

    2019-09-16 #1171 从链表中删去总和值为零的连续节点 #1170 比较字符串最小字母出现频次 #1169 查询无效交易 #226 翻转二叉树 2019-09-15 #1190 反转每对括 ...

  9. ➡️➡️➡️leetcode 需要每天打卡,养成习惯

    目录 待完成的 完成的 0204 0203 以前 java 的 ! 的操作 不像 c 那样自由,!不要使用在int 变量上 c ^ 是异或操作 体会:c中,malloc 后的新建的数组,默认不是0(j ...

随机推荐

  1. 性能分析 | Linux 内存占用分析

    这篇博客主要介绍 linux 环境下,查看内存占用的两种方式:使用 ps,top等命令:查看/proc/[pid]/下的文件.文章简要介绍了命令的使用方法与一些参数意义,同时对/proc/[pid]/ ...

  2. mybatis映射文件祥解(StudentMapper.xml)

    1)以下是StudentMapper.xml文件,提倡放在与实体同目录下,文件名任意 <?xml version="1.0" encoding="UTF-8&quo ...

  3. kafka default partitioner java版本和scala版本的不同

    scala import kafka.utils._ class DefaultPartitioner(props: VerifiableProperties = null) extends Part ...

  4. Linux系统调优相关工具

    一.系统调优概述 系统的运行状况: CPU -> MEM -> DISK*-> NETWORK -> 应用程序调优 分析是否有瓶颈(依据当前应用需求) 调优(把错误的调正确) ...

  5. 公式test

  6. SQL Server 修改默认实例

    有一台服务器,里面装了两个版本的数据库,一个2008(实例名称为MSSQLSERVER),一个2017(实例名称为MSSQLSERVER01): Sql server 数据库可以安装多个数据库实例,但 ...

  7. 文件上传and富文本页面

    文件上传功能: 1.首先在index.jsp的界面上初始化一个表单. <body> <form enctype="multipart/form-data" act ...

  8. document.documentElement.clientHeight 和 document.body.clientHeight

    document.documentElement.clientHeight 和 document.body.clientHeight 介绍 在进行一些网页效果处理的时候,经常碰到document.do ...

  9. Linux中权限控制ACL命令

    很多小伙伴觉得,Linux的权限管理命令不就是chown和chmod命令吗,什么时候有了ACL了? 什么是ACLACL是访问控制列表(Access Control List)的缩写,主要的目的是在提供 ...

  10. 一、linux基础命令

    一. 常用系统工作命令 1.echo 命令 ​ echo命令用于在终端输出字符串或者变量提取后的值 ​ echo $SHELL 2.date命令 ​ date命令用于显示及设置系统的时间或者日期 参数 ...