2列中的大查询枢轴多列
我如何在大查询中进行转换/枢纽:
从此
solution sentiment groups feeling playing doing
I am good positive ['good', 'am'] 1 0 0
I am playing positive ['playing', 'am'] 0 1 1
She is running positive ['running', 'she] 0 1 0
He is not eating negative ['eating'] 1 0 1
:
solution sentiment groups name value
I am good positive ['good', 'am'] feeling 1
I am good positive ['good', 'am'] playing 0
I am good positive ['good', 'am'] doing 0
I am playing positive ['playing', 'am'] feeling 0
I am playing positive ['playing', 'am'] playing 1
I am playing positive ['playing', 'am'] doing 1
She is running positive ['running', 'she] feeling 0
She is running positive ['running', 'she] playing 1
She is running positive ['running', 'she] doing 1
He is not eating negative ['eating'] feeling 1
He is not eating negative ['eating'] playing 0
He is not eating negative ['eating'] doing 1
我尝试过这样的方法,但是我缺少 name
列...静止看起来不错。
SELECT solution, sentiment, groups, value
FROM table
LEFT JOIN UNNEST ([feeling, playing doing] ) AS value
我尝试过这样的尝试以获取 name
列,但由于给出错误的结果而行不通:
SELECT solution, sentiment, groups, value, name
FROM table,
UNNEST (['feeling', 'playing','doing']) AS name
LEFT JOIN UNNEST ([feeling, playing, doing] ) AS value
可能需要 unnest
name
列以一种很好的方式。
如何创建名称
列?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用为此:
返回
您使用
unnest
也可以工作的想法,您只需要将name
和value
保留在一个中单个数组:You can use the
UNPIVOT
operator for this:returns
Your idea of using
UNNEST
can also work, you just need to keep bothname
andvalue
in a single array: