Oracle PIVOT问题(结果中的空转轴列)

时间:2011-11-23 10:01:38

标签: sql oracle plsql oracle11g pivot

我在使用Oracle时遇到了奇怪的问题,而我尝试了PIVOT。基本上它为所有旋转列返回NULL,而它不应该

WITH 
    "Customer" AS (
        SELECT * FROM "doCustomer" WHERE __some_conditions_here__
    )
SELECT 
    *
FROM
    "Customer"
PIVOT (
    MIN("ChargeCommission")   AS "ChargeCommission"
    FOR ("Index") IN (
        01 AS C01, 02 AS C02, 03 AS C03, 04 AS C04, 05 AS C05, 06 AS C06, 07 AS C07, 08 AS C08, 09 AS C09, 10 AS C10,
        11 AS C11, 12 AS C12, 13 AS C13, 14 AS C14, 15 AS C15, 16 AS C16, 17 AS C17, 18 AS C18, 19 AS C19, 20 AS C20
    )
)

“客户”始终返回非空数据,因此数据没有问题。 但是整个查询的结果取决于我在some_conditions_here中输入的内容。我发现依赖 - “客户”中的数据较少 - >少空。 我知道我可以重写这个查询,它会使用decode / group by,但我只是好奇它为什么会这样。 Oracle的版本是11g。

1 个答案:

答案 0 :(得分:-1)

<FOR ("Index") IN (
    01 AS C01, 02 AS C02, 03 AS C03, 04 AS C04, 05 AS C05, 06 AS C06, 07 AS C07, 08 AS C08, 09 AS C09, 10 AS C10,
    11 AS C11, 12 AS C12, 13 AS C13, 14 AS C14, 15 AS C15, 16 AS C16, 17 AS C17, 18 AS C18, 19 AS C19, 20 AS C20
)>

试试这个,不使用别名......它应该可以工作