首页 > 技术文章 > mysql 查询奇偶数

cat520 2019-01-24 14:35 原文

今天在LeetCode上看到一道sql的题目。

查询ID为奇数的记录。以前没想过这种情况,惭愧。

select id,movie,description,rating from cinema
where description != 'boring'
and id&1
order by rating desc

 

查找id为奇数的行:

 select * from tablewhere id&1 ;

查找id为偶数的行:

select * from table where id=(id>>1)<<1;

2.conv 函数:二进制,八进制,十六进制,十进制之间的转换

二进制--》十进制:

select conv(101010,2,10);

十进制--》十六进制:

select conv(999,10,16);

 

推荐阅读