需要使新列可查询

时间:2015-04-24 13:03:40

标签: sql

我创建了列frfpost_short,但现在我无法在查询中使用该列。

select t.corridor,
s.corridor_code_rb,t.roadway,s.SVYLENG2012,
round(cast(t.frfpost as float),3)) as frfpost_short,
s.FRFPOST,s.BEG_GN
from SEC_FILE_IMPORT_2014 t,NORTH_VAN_DATA_VIEW_MOD_032015 s,
where frfpost_short = s.FRFPOST -- This line is causing problems
                                -- I would like to make frfpost_short queryable
and t.corridor = s.CORRIDOR_CODE
order by 1

2 个答案:

答案 0 :(得分:2)

使用子查询或重复表达式。 select中无法使用where中定义的别名:

select t.corridor,
       s.corridor_code_rb,t.roadway, s.SVYLENG2012,
       round(cast(t.frfpost as float), 3) as frfpost_short,
       s.FRFPOST, s.BEG_GN
from SEC_FILE_IMPORT_2014 t join
     NORTH_VAN_DATA_VIEW_MOD_032015 s
     on round(cast(t.frfpost as float), 3) = s.FRFPOST and
        t.corridor = s.CORRIDOR_CODE
order by 1

我修复了您的查询。特别要学会使用明确的join语法。

答案 1 :(得分:0)

您不能在where子句中使用别名,您需要使用以下解决方案

select t.corridor,
s.corridor_code_rb,t.roadway,s.SVYLENG2012,
round(cast(t.frfpost as float),3)) as frfpost_short,
s.FRFPOST,s.BEG_GN
from SEC_FILE_IMPORT_2014 t,NORTH_VAN_DATA_VIEW_MOD_032015 s,
where round(cast(t.frfpost as float),3)) = s.FRFPOST 
and t.corridor = s.CORRIDOR_CODE
order by 1