第二個查詢的平均基本上就是你想要的。但是,一旦您開始在SQL中使用雙引號標識符,這些標識符就會區分大小寫:"alias"
是與alias
不同的名稱(因爲alias
與ALIAS
相同)。
所以你需要在整個查詢中使用雙引號:
select avg("alias")
from (
select avg(valoare) as "alias"
from note
where nr_matricol=111 group by ID_CURS
)
另一種選擇是使用不需要引用一個名字:
select avg(avg_valoare)
from (
select avg(valoare) as avg_valoare
from note
where nr_matricol=111 group by ID_CURS
)
雖然不是必需的Oracle爲派生表提供別名也是很好的編碼風格。
select avg("alias")
from (
select avg(valoare) as "alias"
from note
where nr_matricol=111 group by ID_CURS
) x --<<< here
注意,Oracle不會不支持AS
關鍵字爲表的別名,所以你不能派生表的別名使用) as x
。
添加一個字母'了'在年底,也將努力 – cha