【问题标题】:In SQL, is there a way to split up a column in SQL that is stored as a list?在 SQL 中,有没有办法拆分 SQL 中存储为列表的列?
【发布时间】:2020-11-12 08:57:27
【问题描述】:

我目前有一个表,该表有一个以列表形式存储的列,无论出于何种原因。它看起来如下:

Symbol      Exchange             Price
AAPL        [NYSE, CHX, PHLX]    22.02 
AAPL        [BSE, MS4X]          23.11

有没有办法使用 SQL 分解表,以便将列扩展为如下内容:

Symbol      Exchange       Price
AAPL        NYSE           22.02 
AAPL        CHX            22.02
AAPL        PHLX           22.02
AAPL        BSE            23.11
AAPL        MS4X           23.11

基本上,目标是分解交换列,以便它有自己的单独条目作为列表。

谢谢

【问题讨论】:

  • exchange的数据类型是什么?

标签: sql presto apache-zeppelin


【解决方案1】:

假设是数组,可以使用unnest()

select t.symbol, u.exchange, t.price
from t cross join
     unnest(t.exchanges) u(exchange);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-13
    • 1970-01-01
    • 2022-06-11
    相关资源
    最近更新 更多