问题描述:
case后的字段,加表名时,会报错,如下:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.type
FROM
agency_vms' at line 7, Time: 0.024000s
如下代码有问题:
SELECT agency_name, agency_vms.type as adbw, case agency_vms.type when 'PCS' then '审方机构' when 'VS' then '复诊机构' end as agency_vms.type FROM agency_vms
解决方案:
case后的字段用表名.字段名,end后的用重命名字段
SELECT agency_name, agency_vms.type as adbw, case agency_vms.type when 'PCS' then '审方机构' when 'VS' then '复诊机构' end as adbw -- 将end后的改为重命名字段 FROM agency_vms