将表格汇总到一个列中,然后将其加入现有的选择语句以保留一对一的关系
如何将表的多行汇总到单列中,然后将表与现有的选择语句加入以保持一对一的关系?
我在Impala中有一个SQL语句,该语句在inc
上连接了两个表。每个表字段都有一个inc
,因此JOIN在两个表之间创建一对一的关系。用于连接表tbl_a
to tbl_b
的SQL如下:
SELECT INC_TBL_A, CITY_TBL_B
FROM TBL_A.INC_TBL_A
LEFT OUTER JOIN TBL_B
ON
TBL_A.INC_TBL_A = TBL_B.TBL_B.INC
AND TBL_B.TBL_B.XYZ = 17000
输出:
INC_TBLE_A CITY_TBL_B
INC1 SYDNEY
INC2 HONG KONG
INC3 LONDON
我需要介绍另一个表,该表有许多值(MANE_FIELD_C
)一个Inc(inc_c
):
INC_C MANY_FIELD_C
INC1 , A
INC1 , B
INC1 C
INC1 C
INC1 , D
INC1 , E
INC2 34W
INC2 c
INC3 ~5
INC3 ^d
如何将字段滚动到
滚动UP_C
?
INC_C ROLLED UP_C
INC1 , A , B C C , D , E
INC2 34W c
INC3 ~5 ^d
How to aggregate a table's multiple rows into a single column, then join to an existing select statement to preserve the one to one relationship?
I have an SQL statement in Impala which joins two tables on INC
. There is one INC
for each of the tables field's so the join creates a one to one relationship between the two tables. The SQL for joining Table TBL_A
to TBL_B
is as follows:
SELECT INC_TBL_A, CITY_TBL_B
FROM TBL_A.INC_TBL_A
LEFT OUTER JOIN TBL_B
ON
TBL_A.INC_TBL_A = TBL_B.TBL_B.INC
AND TBL_B.TBL_B.XYZ = 17000
Output:
INC_TBLE_A CITY_TBL_B
INC1 SYDNEY
INC2 HONG KONG
INC3 LONDON
I need to introduce another table, which has many values (MANY_FIELD_C
) for one INC (INC_C
):
INC_C MANY_FIELD_C
INC1 , A
INC1 , B
INC1 C
INC1 C
INC1 , D
INC1 , E
INC2 34W
INC2 c
INC3 ~5
INC3 ^d
How do I roll up field MANY_FIELD_C
into ROLLED UP_C
?
INC_C ROLLED UP_C
INC1 , A , B C C , D , E
INC2 34W c
INC3 ~5 ^d
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过
group_concat
函数解决此问题:I resolved this through the
GROUP_CONCAT
function: