Example of an Oracle PIVOT clause with subquery

后端 未结 2 1021
心在旅途
心在旅途 2021-02-02 09:55

Oracle\'s definition of the PIVOT clause specifies that there is a possibility to define a subquery in the IN clause. A fictional example of what I would imagine th

2条回答
  •  再見小時候
    2021-02-02 10:27

    Apparently, I was too lazy to read to the end of the documentation... Further down, the documentation states:

    subquery A subquery is used only in conjunction with the XML keyword. When you specify a subquery, all values found by the subquery are used for pivoting. [...]

    This will work

    PIVOT XML (AVG(salary) FOR (company) IN (SELECT DISTINCT company FROM companies))
    

    See the full documentation

    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_10002.htm#CHDFAFIE

提交回复
热议问题