【问题标题】:Pivot with subquery oracle sql使用子查询 oracle sql 进行数据透视
【发布时间】:2014-09-25 04:24:44
【问题描述】:

我正在尝试使用 pivot 来显示我的信息。我想使用子查询来选择报告中的列:

select * from 
(select continent, country, population
 from continents, countries
 where continents.id=countries.id
 )
 pivot (sum(population) for country in (select distinct country from countries)

当我尝试使用子查询获取国家/地区列表时,我不断收到错误消息。

我尝试使用数据透视 XML,但这也不起作用,因为它返回了无意义的 xml 代码。 我想看看实际数字!

【问题讨论】:

标签: sql oracle pivot unpivot


【解决方案1】:

您不能在 PIVOT 子句中使用子查询的结果,因为列需要静态定义。但是您可以使用子查询的结果生成动态 SQL,然后通过立即执行来执行它。

【讨论】:

    猜你喜欢
    • 2011-06-18
    • 2018-11-05
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 2020-09-24
    相关资源
    最近更新 更多