如何在Oracle SQL中转置和枢转
我正在尝试从表中翻转数据,这是一个屏幕截图,可以解释它的外观。 在左边,我们有数据库表,以及我想推出它的正确性
尝试使用枢轴和案例语句,但无法获得我需要的视图,请指导
i am trying to flip the data from a table , here is a screenshot to explain how it looks.
on the left we have database table and on right how i want to derive it
i have so far tried using pivot, and case statements but was not able to get the view i need, please guide
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这通常是在演示层中执行的任务,而不是在数据库中执行的任务。
如果必须在SQL中进行操作,则可以使用:
对于示例数据,输出:哪个:
注意:您必须对日期值进行核对编码。无法使用
Pivot
语句动态提供它们。如果需要动态枢轴,请查看这个问题(然后忽略它并在演示文稿中执行任务,不在sql)。 >
This is typically a task that is performed in the presentation-layer and not in the database.
If you must do it in SQL then you can use:
Which, for the sample data, outputs:
Note: You must hard-code the date values. They cannot be provided dynamically using a
PIVOT
statement. If you want a dynamic pivot then look at this question (and then ignore it and perform the task in the presentation-layer and not in SQL).db<>fiddle here