【问题标题】:how can I turn column into rows in presto?如何在 presto 中将列转换为行?
【发布时间】:2020-12-24 10:04:24
【问题描述】:

我想将列转换为新行并保存值。

例如:

之前

NAME  COMDEDY  HORROR  ROMANCE
brian    10     20     14
tom      20     10     11

之后

NAME    GANRE    RATING
brian   comedy     10
brian   horror     20
brian   romance    14
tom     comedy     20
tom     horror     10
tom     romance    11

如果我不能用 prestodb 做到这一点,我至少需要用 python pandas 做到这一点

【问题讨论】:

  • Python pandas 代码作为解决方案添加!

标签: python sql pandas presto unpivot


【解决方案1】:

你可以使用 presto sql:

SELECT t1.name, t2.genre, t2.rating
FROM table t1
CROSS JOIN unnest (
  array['comedy', 'horror', 'romance'],
  array[comedy, horror, romance]
) t2 (genre, rating)

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 1970-01-01
    • 2019-08-12
    • 2019-10-03
    • 2020-11-22
    • 2018-04-03
    • 1970-01-01
    • 2021-11-04
    • 2022-01-18
    相关资源
    最近更新 更多