Sql 无法在Group By-Oracle中添加子查询表达式

Sql 无法在Group By-Oracle中添加子查询表达式,sql,oracle,Sql,Oracle,我有如下疑问: 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. 00

我有如下疑问:

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
我认为这是因为在GROUPBY中添加的子查询中的where子句

请参阅子查询,从表1中选择*,其中field=a和field2=b具有父表中的a和b字段

请提供帮助。

如果子查询从表1中选择*,其中字段=a和字段2=b 如果只返回一个值,则此操作应有效:

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
但是如果子查询从表1中选择*,其中field=a和field2=b 如果未仅返回一个值,则会出现以下错误:

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

为什么在不涉及聚合函数的情况下进行分组

改为使用DISTINCT,即

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

尝试将group by中的子查询替换为别名,\u column它不工作。。当我在谷歌上搜索时,它说我必须把所有的子查询放在group By中,因为子查询中连接了多个表。我在问题中没有提到这一点。您是否介意设置以调试您的问题?您使用子查询分组?这是办不到的。。从字面上来说,对一些数据进行分组,你从ur from和WHERE子句中得到了什么。@Sahal好的,你试过我建议的查询了吗?这个答案与这个问题无关。