SQL语句求解
select c.sLSight from D_PatientCaseInfo c where c.nPID='1503571' 这个语句 查询到结果:
0.05 0.6
指数 0.4
查询结果正确,但是为什么接下来的查询语句就出问题了?select
(case when (sLSight = '指数') then '0.001'
when (sLSight = '手动') then '0.002'
when (sLSight = '光感') then '0.003'
when (sLSight = '无光感') then '0.004'
when (sLSight = '不配合') then '0.005'
when (sLSight = '义眼') then '0.006'
else 0 end) as '左眼视力,
(case when (sRSight = '指数') then '0.001'
when (sRSight = '手动') then '0.002'
when (sRSight = '光感') then '0.003'
when (sRSight = '无光感') then '0.004'
when (sRSight = '不配合') then '0.005'
when (sRSight = '义眼') then '0.006'
else 0 end) as '右眼视力 from D_PatientCaseInfo c where c.nPID='1503571'
查询的结果为什么都是
0 0
0 0呢?
------解决方案--------------------
按楼主描述模拟:
create table D_PatientCaseInfo(
nPID varchar(50),
sLSight varchar(50),
sRSight varchar(50)
)
insert into D_PatientCaseInfo(nPID,sLSight,sRSight) values('1503571','指数','指数')
insert into D_PatientCaseInfo(nPID,sLSight,sRSight) values('1503572','手动','手动')
insert into D_PatientCaseInfo(nPID,sLSight,sRSight) values('1503573','光感','光感')
insert into D_PatientCaseInfo(nPID,sLSight,sRSight) values('1503574','无光感','无光感')
insert into D_PatientCaseInfo(nPID,sLSight,sRSight) values('1503575','不配合','不配合')
insert into D_PatientCaseInfo(nPID,sLSight,sRSight) values('1503576','义眼','义眼')
select
(
case
when (sLSight = '指数') then 0.001
when (sLSight = '手动') then 0.002
when (sLSight = '光感') then 0.003
when (sLSight = '无光感') then 0.004
when (sLSight = '不配合') then 0.005
when (sLSight = '义眼') then 0.006
else 0 end) as '左眼视力',
(case when (sRSight = '指数') then 0.001
when (sRSight = '手动') then 0.002
when (sRSight = '光感') then 0.003
when (sRSight = '无光感') then 0.004
when (sRSight = '不配合') then 0.005
when (sRSight = '义眼') then 0.006
else 0 end) as '右眼视力'
from D_PatientCaseInfo c where c.nPID='1503571'