Group by alias (Oracle)(按别名分组 (Oracle))
问题描述
如何使用别名对查询进行分组",例如:
How to 'group by' a query using an alias, for example:
select count(*), (select * from....) as alias_column
from table
group by alias_column
我收到alias_column":INVALID_IDENTIFIER 错误消息.为什么?如何对该查询进行分组?
I get 'alias_column' : INVALID_IDENTIFIER error message. Why? How to group this query?
推荐答案
select
count(count_col),
alias_column
from
(
select
count_col,
(select value from....) as alias_column
from
table
) as inline
group by
alias_column
如果您在 GROUP BY 子句中重复相应的表达式,则分组通常有效.仅提及别名是不可能的,因为 SELECT 步骤是执行查询的最后一步,分组发生得更早,当别名尚未定义时.
Grouping normally works if you repeat the respective expression in the GROUP BY clause. Just mentioning an alias is not possible, because the SELECT step is the last step to happen the execution of a query, grouping happens earlier, when alias names are not yet defined.
要对子查询的结果进行 GROUP BY,您将不得不绕道而行并使用嵌套查询,如上所述.
To GROUP BY the result of a sub-query, you will have to take a little detour and use an nested query, as indicated above.
这篇关于按别名分组 (Oracle)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:按别名分组 (Oracle)


基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01