使用select语句创建的字段上的标识符错误无效

时间:2011-10-11 20:21:46

标签: sql oracle10g identifier

为什么sql以后不起作用?

select
    a.field1, a.field2, a.field3,
    (select count(*)
        from table2 b
        where b.field1 = a.field1
    ) as field4,
    (select count(*)
        from table3 b
        where b.field1 = a.field1
    ) as field5,
    (select count(*)
        from table4 b
        where b.field1 = a.field1
    ) as field6,
from table1 a
order by field4

Oracle说:ORA-00904:“field4”:标识符无效

1 个答案:

答案 0 :(得分:1)

试着把它包起来

select * from 
(    
select
    a.field1, a.field2, a.field3,
    (select count(*)
        from table2 b
        where b.field1 = a.field1
    ) as field4,
    (select count(*)
        from table3 b
        where b.field1 = a.field1
    ) as field5,
    (select count(*)
        from table4 b
        where b.field1 = a.field1
    ) as field6,
from table1 a
)
order by field4