2014-06-13 46 views
0

我有類似下面的查詢,無法在組中添加子查詢表達 - 甲骨文

select a,b,c, (select h from table 1 where field = a and field2 = b) as alias_column, d 
from table 
group by a,b,c, (select h from table 1 where field = a and field2 = b) , d 

我越來越喜歡錯誤,

ORA-22818: subquery expressions not allowed here 
22818. 00000 - "subquery expressions not allowed here" 
*Cause: An attempt was made to use a subquery expression where these 
      are not supported. 
*Action: Rewrite the statement without the subquery expression. 
Error at Line: 84 Column: 2 

我想這是因爲在子查詢where clause那被添加在group by

查看子查詢(select * from table 1 where field = a and field2 = b)ab字段從父ta BLE。

請幫忙。

+0

嘗試更換子查詢在組alias_column – Uriil

+0

它不工作..當我谷歌它說,我必須把所有的子查詢組 – Sahal

+0

有多個表加入子查詢。我在問題中沒有提到這一點。 – Sahal

回答

0

如果子查詢() 是隻返回一個值,那麼這應該工作:

select * from 
(select a,b,c, (select * from table 1 where field = a and field2 = b) as alias_column, d 
from table) 
group by a,b,c, alias_column , d 

但是,如果子查詢() 是不是隻返回一個值,那麼你會得到如下錯誤:

ORA-01427: single-row subquery returns more than one row 
01427. 00000 - "single-row subquery returns more than one row" 
+0

我編輯了我的問題 – Sahal

+0

@Sahal ok,您是否嘗試過使用我建議的查詢? – Arijit

-2

爲什麼在沒有涉及集合函數的情況下進行分組?

使用DISTINCT代替,即

選擇DISTINCT A,B,C,(從表1中選擇*,其中字段= a和FIELD2 = b)的alias_column,d 從表