使用SQL生成数据透视表

时间:2016-04-13 08:59:16

标签: sql oracle

我正在尝试使用SQL来生成数据透视表。但无论我如何尝试,我都会继续从oracle获得 ORA-00936:缺少表达式错误。

这是我的问题:

SELECT * FROM (SELECT HOS_PAY_ID, AMOUNT FROM HOSPITAL_PAYMENT)
PIVOT (SUM (AMOUNT) FOR AMOUNT IN ([10000],[8000],[7000],[9000],[11000],[13000]) AS TEST
ORDER BY HOS_PAY_ID;

这是我的数据:

enter image description here

谢谢。

1 个答案:

答案 0 :(得分:1)

试试这个

SELECT * FROM 
(
     SELECT HOS_PAY_ID, AMOUNT 
     FROM HOSPITAL_PAYMENT
)
PIVOT (
        SUM (AMOUNT) FOR AMOUNT IN (10000,8000,7000,9000,11000,13000)
      )
ORDER BY HOS_PAY_ID;