时间:2021-07-01 10:21:17 帮助过:123人阅读
下面小编就为大家带来一篇用mysql 查询奇偶数的实例代码。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
1:查找id为奇数的行
引用
mysql> select * from forum_dummy where id&1 ; +----+-----------+------------+ | id | user_name | dummy_name | +----+-----------+------------+ | 1 | yang | ting | | 3 | yang3 | ting3 | +----+-----------+------------+ 2 rows in set (0.00 sec)
2:查找id为偶数的行
引用
mysql> select * from forum_dummy where id=(id>>1)<<1 ; +----+-----------+------------+ | id | user_name | dummy_name | +----+-----------+------------+ | 2 | yang1 | ting1 | | 4 | yang4 | ting4 | +----+-----------+------------+ 2 rows in set (0.00 sec)
3:conv 函数:二进制,八进制,十六进制,十进制之间的转换
1)二进制--》十进制
引用
mysql> select conv(101010,2,10); +-------------------+ | conv(101010,2,10) | +-------------------+ | 42 | +-------------------+ 1 row in set (0.00 sec) 2)十进制--》十六进制 引用 mysql> select conv(999,10,16); +-----------------+ | conv(999,10,16) | +-----------------+ | 3E7 | +-----------------+ 1 row in set (0.00 sec)
以上就是用mysql 查询奇偶数的实例代码的详细内容,更多请关注Gxl网其它相关文章!