Is there an Oracle SQL query that aggregates multiple rows into one row?(是否有将多行聚合为一行的 Oracle SQL 查询?)
问题描述
我有一张看起来像这样的表格:
I have a table that looks like this:
A 1
A 2
B 1
B 2
我想生成一个如下所示的结果集:
And I want to produce a result set that looks like this:
A 1 2
B 1 2
是否有可以执行此操作的 SQL 语句?我正在使用 Oracle.
Is there a SQL statement that will do this? I am using Oracle.
相关问题:
- 从单行返回多行我的问题与这个问题的反面很接近.
- 使用 LINQ 连接 这正是我想要做的,但没有 LINQ.
- Returning multiple rows from a single row My question is close to the opposite of this question.
- Use LINQ to concatenate This is exactly what I want to do, but without LINQ.
推荐答案
这取决于您使用的 Oracle 版本.如果它支持 wm_concat() 函数,那么你可以简单地做这样的事情:
It depends on the version of Oracle you're using. If it supports the wm_concat() function, then you can simply do something like this:
SELECT field1, wm_concat(field2) FROM YourTable GROUP BY field2;
wm_concat() 基本上就像 group_concat() 在 MySQL 中.它可能没有记录,所以启动你的旧 sqlplus 看看它是否在那里.
wm_concat() basically works just like group_concat() in MySQL. It may not be documented, so fire up ye olde sqlplus and see if it's there.
如果它不存在,那么您需要自己实现一些等效的东西.您可以在字符串聚合页面中找到有关如何执行此操作的说明在 oracle-base.com.
If it isn't there, then you'll want to implement something equivalent yourself. You can find some instructions on how to do this in the string aggregation page at oracle-base.com.
这篇关于是否有将多行聚合为一行的 Oracle SQL 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有将多行聚合为一行的 Oracle SQL 查询?
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
