2015.10.30
今天写了个统计男女比例的sql:
SELECT "SUM"(CASE WHEN p.PSRD_GENDER='M' then 1 else 0 end) as male,
"SUM"(CASE WHEN p.PSRD_GENDER='F' then 1 else 0 end) as female
FROM VIEW_VPS_TA_PSR as p;
结果一直报错,[Err] ORA-00933: SQL command not properly ended,结果后来发现是结尾部分有问题,
修改后:
SELECT "SUM"(CASE WHEN PSRD_GENDER='M' then 1 else 0 end) as male,
"SUM"(CASE WHEN PSRD_GENDER='F' then 1 else 0 end) as female
FROM VIEW_VPS_TA_PSR ;
总结:sql结尾如果没有其他条件,则as用起来不妥,会导致结尾没有正确结束的错误。