Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6 有趣的电影 #9

Open
astak16 opened this issue Jan 6, 2022 · 0 comments
Open

6 有趣的电影 #9

astak16 opened this issue Jan 6, 2022 · 0 comments
Labels

Comments

@astak16
Copy link
Owner

astak16 commented Jan 6, 2022

题目

找出影片中非 boring 并且 id 为奇数的影片,结果按照等级 rating 排序

create table cinema (
	id int,
	movie varchar(255),
	description varchar(255),
	rating float
);

insert into cinema values
(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', 'Insteresting', 9.1);

SQL

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

解析

如何计算奇数呢?

  • mod(x, 2) = 1 ,如果余数是 1 就是奇数。
  • power(-1, x) = -1 , 如果结果是 -1 就是奇数
  • x % 2 = 1 ,如果余数是 1 就是奇数。
  • x & 1 = 1 ,如果是 1 就是奇数
  • x regexp '[1, 3, 5, 7, 9]$' = 1 如果为 1 就是奇数
  • x>>1<<1 != x 如果右移一位在左移一位不等于原值,就是奇数
@astak16 astak16 added the 简单 label Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant