2011-10-11 35 views
1

爲什麼sql波紋管不起作用?使用select語句創建的字段上的標識符錯誤無效

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: 「字段4」:無效的標識符

回答

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