sql - 将包含列值的非固定值的行动态转置为 Oracle 中的列名
问题描述
我有一个查询结果(在连接多个具有主子关系和查找关系的表时),它返回具有一些重复列值的多行。示例结果集如下所示。
ReviewID | UserId | ProductId | ReviewDate | UserAgent | ReviewQuestionId | ReviewQuestionText | ReviewResponse | ReviewCommentId | ReviewComment
1 | 40001 | 2005 | 01/01/2010 | Mobile | 45 | Product_Availability | 10 | 10002 | I am happy with the product xxxxx
1 | 40001 | 2005 | 01/01/2010 | Mobile | 46 | Location_Access | 5 | 10002 | I am happy with the product xxxxx
1 | 40001 | 2005 | 01/01/2010 | Mobile | 47 | Staff | 8 | 10002 | I am happy with the product xxxxx
1 | 40001 | 2005 | 01/01/2010 | Mobile | 48 | Shipping | 9 | 10002 | I am happy with the product xxxxx
您可以看到,除了 ReviewQuestionId | 评论问题文本 | ReviewResponse,所有其他列都在重复。我想要 1 行中的响应,其中 ReviewQuestionText 将是列名,ReviewResponse 是该列中的值。
ReviewID | UserId | ProductId | ReviewDate | UserAgent | Product_Availability | Location_Access | Staff| Shipping | ReviewCommentId | ReviewComment
1 | 40001 | 2005 | 01/01/2010 | Mobile | 10 | 5 | 8 | 9 | 10002 | I am happy with the product xxxxx
ReviewQuestionId 和 ReviewQuestionText 列未针对评论进行修复。根据进行审查的产品和年份,问题集是不同的,因此我无法修复我的枢轴中的列。
解决方案
推荐阅读
- ocaml - 什么是 PPX?
- javascript - 将 keras 模型加载到 tfjs 会导致输入形状不匹配
- jenkins - 无法获取詹金斯的用户名和密码
- docker - Docker NGINX 反向代理 502 VM 上的错误网关
- python - 如何在Python中的特定行下远程添加一行
- wordpress - 无法通过 get_post_meta() 从自定义插件中检索 ACF 字段
- opentbs - 使用 ope=tbs:num 时是否可以更改 opentbs 中的格式?
- reactjs - 当要返回的对象在其中更新时,如何使异步函数按顺序工作
- amazon-s3 - 动态路由静态导出使得在 S3 + Cloudfront 中难以路由 [NextJS]
- r - R:选择数据框列的一列