数据库
首页 > 数据库> > mysql查询性别是否跟身份证一致

mysql查询性别是否跟身份证一致

作者:互联网

select * from (select
name,
gender % 2 gender,
agentcode,
certno,
SUBSTR( certno, LENGTH( certno )- 1, 1 ) sexNum,
SUBSTR( certno, LENGTH( certno )- 1, 1 )% 2 sexType,
(case ((gender % 2)=SUBSTR( certno, LENGTH( certno )- 1, 1 )% 2) when true then '1' else '0' end) result
FROM
t_agent ) a where a.result = '0'

 

说明:身份证倒数第二位为奇数:男;偶数:女

标签:gender,certno,agent,SUBSTR,LENGTH,身份证,mysql,性别
来源: https://www.cnblogs.com/Marlo/p/15838575.html