【发布时间】:2021-06-14 05:35:41
【问题描述】:
我是一个 SQL 菜鸟。
如何在显示其他列值的同时连接特定字段的列值?
我会尽力展示一个简化的例子。
假设我有下表:
表 A
| Name | Address | Value1 | Value2 | Value3 | |
|---|---|---|---|---|---|
| Sam | 123 Main Street | sam@coporate.com | 34 | 51 | 39 |
| Peter | 789 High Street | peter@coporate.com | 73 | 05 | 59 |
| Sam | 123 Main Street | sam@coporate.com | 43 | 12 | 84 |
| Sally | 456 State Street | sally@coporate.com | 35 | 76 | 23 |
| Sally | 456 State Street | sally@coporate.com | 77 | 34 | 18 |
| Peter | 789 High Street | peter@coporate.com | 32 | 14 | 54 |
| Sally | 456 State Street | sally@coporate.com | 64 | 49 | 23 |
预期输出
| Name | Address | Value1 | Value2 | Value3 | |
|---|---|---|---|---|---|
| Sam | 123 Main Street | sam@coporate.com | 34,43 | 51,12 | 39,84 |
| Sally | 456 State Street | sally@coporate.com | 35,64,77 | 76,49,34 | 23,23,18 |
| Peter | 789 High Street | peter@coporate.com | 32,73 | 14,05 | 54,59 |
我尝试使用LISTAGG,但我遇到的问题是我无法显示名称、地址和电子邮件字段。请帮助并提前感谢您!
【问题讨论】:
-
您需要为此函数添加analytic clause 而不是
group by。
标签: sql oracle aggregate string-concatenation string-aggregation