oracle 数据透视表错误 56901 非常量表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26748210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:36:15  来源:igfitidea点击:

Pivot Table Error 56901 non-constant expression

sqloraclepivot

提问by user3729062

I need to create a pivot table of average salary in Division_IDas Row and Job_IDas Column using data in employees2table. So far I have:

我需要使用表中的数据Division_ID在行和Job_ID列中创建一个平均工资数据透视employees2表。到目前为止,我有:

SELECT * 
FROM (
SELECT Division_ID, Salary, Job_ID
FROM Employees2
)
PIVOT (
AVG(Salary) FOR Job_ID IN (ENG, TEC, MGR)
)
ORDER BY Job_ID

I get the error, "non-constant expression is not allowed for pivot|unpivot values"

我收到错误消息,“数据透视|反透视值不允许使用非常量表达式”

What am I doing wrong? Most the examples I can find online deal with Numerical values after the IN statement, do I need to do something different since im working with text/string?

我究竟做错了什么?我可以在网上找到的大多数示例都在 IN 语句之后处理数值,因为我使用文本/字符串,所以我需要做一些不同的事情吗?

回答by Nishanthi Grashia

Use below Query.

使用下面的查询。

SELECT *    FROM (
    SELECT Division_ID, Salary, Job_ID
    FROM Employees2
)  
PIVOT 
(
     AVG(Salary) FOR Job_ID IN 
    ('ENG', 'TEC', 'MGR')     ------------> Change done here.....
)
ORDER BY Job_ID

The values ENG, TECand MGRneed to be surrounded by single quotes to be considered as constant values.

values ENG, TECandMGR需要用单引号括起来才能被视为常量值。