我有以下查询,但是我想在case语句中使用子查询。我尝试了不同的东西,但没有快乐。请有人建议
select a.PARAMID, a.PERSONOPTID, a.paramdate,(case
when (to_char(a.paramdate,'mmdd')>='0301' and to_char(a.paramdate,'mmdd')<='0620') then 'spring' --else 'Summer'
when (to_char(a.paramdate,'mmdd')>='0621' and to_char(a.paramdate,'mmdd')<='0920') then 'Summer' -- else 'Autumn'
when (to_char(a.paramdate,'mmdd')>='0921' and to_char(a.paramdate,'mmdd')<='1130') then 'Autumn' else 'winter'
--when (to_char(a.paramdate,'mmdd')>'1201' and to_char(a.paramdate,'mmdd')<='0228') then 'winter'end
end) from personoptions a, personopt po, person
WHERE a.PARAMID=190 and
a.PERSONOPTID in (select a.PERSONOPTID from personoptions a
where a.paramid=185 and
trunc(a.PARAMDATE) between trunc(sysdate-372)and trunc(sysdate-365)) and
a.PERSONOPTID = po.PERSONOPTID
AND po.PERSONID = person.personid
AND po.PERSONID in ( 12345)
我尝试了什么,
select (case when exists (select personid from ( select person.personid from personoptions a, personopt po, person
WHERE a.PARAMID=190 and
a.PERSONOPTID in (select a.PERSONOPTID from personoptions a
where a.paramid=185 and
trunc(a.PARAMDATE) between trunc(sysdate-372)and trunc(sysdate-365)) and
a.PERSONOPTID = po.PERSONOPTID
AND po.PERSONID = person.personid
AND po.PERSONID in ( 1481198891002120249232017090384761))) then
(case when (to_char(a.paramdate,'mmdd')>='0301' and to_char(a.paramdate,'mmdd')<='0620') then 'spring' --else 'Summer'
when (to_char(a.paramdate,'mmdd')>='0621' and to_char(a.paramdate,'mmdd')<='0920') then 'Summer' -- else 'Autumn'
when (to_char(a.paramdate,'mmdd')>='0921' and to_char(a.paramdate,'mmdd')<='1130') then 'Autumn' else 'winter'
--when (to_char(a.paramdate,'mmdd')>'1201' and to_char(a.paramdate,'mmdd')<='0228') then 'winter'end
end)end) from person
错误:Ora-00904:a.paramdate无效标识符
答案 0 :(得分:0)