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
Pivot Table Error 56901 non-constant expression
提问by user3729062
I need to create a pivot table of average salary in Division_ID
as Row and Job_ID
as Column using data in employees2
table. 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
, TEC
and MGR
need to be surrounded by single quotes to be considered as constant values.
values ENG
, TEC
andMGR
需要用单引号括起来才能被视为常量值。