2

谁能帮我查明为什么这段代码返回 SQL Oracle ORA-00904: invalid indentifier 错误?该查询在没有 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
4

2 回答 2

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'
于 2012-04-30T15:27:45.770 回答
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'
于 2012-04-30T15:49:53.747 回答