We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
找出影片中非 boring 并且 id 为奇数的影片,结果按照等级 rating 排序
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);
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
x & 1 = 1
x regexp '[1, 3, 5, 7, 9]$' = 1
x>>1<<1 != x
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
找出影片中非
boring
并且id
为奇数的影片,结果按照等级rating
排序SQL
解析
如何计算奇数呢?
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
如果右移一位在左移一位不等于原值,就是奇数The text was updated successfully, but these errors were encountered: