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'
说明:身份证倒数第二位为奇数:男;偶数:女