SQL Oracle ORA-00904:无效的标识符错误

时间:2012-04-30 15:25:10

标签: sql oracle

有人可以帮我查明为什么此代码返回SQL Oracle ORA-00904:无效的标识符错误?查询在没有Country ='Argentina'的情况下工作,但我需要按此值过滤。有人能指出我正确的方向吗?

select llattrdata.ID dataid,

max(case when llattrdata.ATTRID = 4 then llattrdata.VALSTR end) Country

from llattrdata, dtree 

where
llattrdata.DEFID = 19400074 and
llattrdata.VERNUM = dtree.VERSIONNUM and
llattrdata.ID = dtree.DATAID and 
Country = 'Argentina'
group by llattrdata.ID

2 个答案:

答案 0 :(得分:4)

在对分组条件进行过滤时,您需要使用having代替where

应该是这样的:

select llattrdata.ID dataid,
        max(case when llattrdata.ATTRID = 4 then llattrdata.VALSTR end) Country
  from llattrdata, dtree 
 where llattrdata.DEFID = 19400074 
   and llattrdata.VERNUM = dtree.VERSIONNUM 
   and llattrdata.ID = dtree.DATAID 
 group by llattrdata.ID
having max(case when llattrdata.ATTRID = 4 then llattrdata.VALSTR end) = 'Argentina'

答案 1 :(得分:0)

也许我错过了什么,但这与以下不一样:

select distinct
  llattrdata.ID     dataid,
  llattrdata.VALSTR Country
from
  llattrdata,
  dtree 
where
  llattrdata.VERNUM        = dtree.VERSIONNUM and
  llattrdata.ID            = dtree.DATAID     and 
  llattrdata.DEFID         = 19400074         and
  llattrdata.ATTRID        = 4                and
  llattrdata.VALSTRCountry = 'Argentina'