判断奇偶数

1、按位与

  select * from cinema WHERE id&1; 

2、id先除以2然后乘2 如果与原来的相等就是偶数

  select * from cinema WHERE id=(id>>1)<<1; 

3、正则匹配最后一位

  select * from cinema WHERE id regexp '[13579]$';
  select * from cinema WHERE id regexp '[02468]$';

4、id计算

  select * from cinema WHERE id%2 = 1;
  select * from cinema WHERE id%2 = 0;

  select * from cinema WHERE mod(id, 2) = 1;
  select * from cinema WHERE mod(id, 2) = 0;

5、1的奇数次方和偶数次方

  select * from cinema WHERE POWER(-1, id) = -1;
  select * from cinema WHERE POWER(-1, id) = 1;

  https://blog.csdn.net/zhazhagu/article/details/80452473

 

posted @ 2021-05-11 14:06  wujingqi  阅读(201)  评论(0编辑  收藏  举报