[英]how can I turn column into rows in presto?
I am working on presto sql and got stucked.我正在处理 presto sql 并被卡住了。
I want to turn column into a new rows and save the values.我想将列变成新行并保存值。
For example:例如:
BEFORE前
NAME COMDEDY HORROR ROMANCE
brian 10 20 14
tom 20 10 11
AFTER后
NAME GANRE RATING
brian comedy 10
brian horror 20
brian romance 14
tom comedy 20
tom horror 10
tom romance 11
I need to do this at least with python pandas ,if I can't do it with prestodb如果我不能用 prestodb 做到这一点,我至少需要用 python pandas 做到这一点
Thanks!谢谢!
You can do it using presto sql:您可以使用 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)
I am working on presto sql and got stucked.我正在处理 presto sql 并被卡住了。
I want to turn column into a new rows and save the values.我想将列转换为新行并保存值。
For example:例如:
BEFORE前
NAME COMDEDY HORROR ROMANCE
brian 10 20 14
tom 20 10 11
AFTER后
NAME GANRE RATING
brian comedy 10
brian horror 20
brian romance 14
tom comedy 20
tom horror 10
tom romance 11
I need to do this at least with python pandas ,if I can't do it with prestodb如果我不能用 prestodb 做到这一点,我至少需要用 python pandas 做到这一点
Thanks!谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.