【问题标题】:how to transpose the queried results from oracle database如何转置oracle数据库中的查询结果
【发布时间】:2011-09-07 22:56:59
【问题描述】:

我想知道如何编写一个 Oracle sql 命令来显示查询结果:

column_name1 column_name2  column_name3
result1_col1 result1_col2  result1_col3
result2_col1 result2_col2  result2_col3
...

而是:

column_name1 result1_col1  result2_col1 ...
column_name2 result1_col2  result2_col2 ...
column_name3 result1_col3  result2_col3 ...

?

我的 oracle 版本是 11.1.0.7.0。

非常感谢!

【问题讨论】:

  • PIVOT 可以将特定数量的行转换为列。如果您想在不知道最终要获得多少列的情况下执行此操作,则需要编写编写代码的代码(也称为动态 sql)。
  • @dems 我也在寻找相同的查询...你能给出一些提示吗?你的建议..意味着代码..如果你有这种代码/与您查询请在此处发布或请为此提供任何好的链接...
  • 查看您之前的评论

标签: sql oracle oracle11g


【解决方案1】:

这个blog post of mine 相当古老,但确实提供了一种动态生成数据透视查询的方法。它是在 PIVOT 子句存在之前编写的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 2015-01-30
    • 2023-03-22
    • 2021-07-21
    • 1970-01-01
    • 2017-10-17
    • 1970-01-01
    相关资源
    最近更新 更多