错误:语法错误在“ OVER”处或附近。 [英] ERROR: syntax error at or near "OVER"
问题描述
我是SQL语言和PostgreSQL的新手。我逐渐熟悉该语言,并遵循PostgreSQL教程,直到陷入关于窗口函数的一章为止(链接文本。我创建了与示例完全相同的表 empsalary:
I'm new to the SQL language and PostgreSQL. I was getting familiar with the language and was following a PostgreSQL tutorial until I got stuck at a chapter about Window Functions (link text. I created the exact same table 'empsalary' as shown in the example:
wtouw=# SELECT * FROM empsalary;
depname | empno | salary
-----------+-------+--------
develop | 11 | 5200
develop | 7 | 4200
develop | 9 | 4500
develop | 8 | 6000
develop | 10 | 5200
personnel | 5 | 3500
personnel | 2 | 3900
sales | 3 | 4800
sales | 1 | 5000
sales | 4 | 4800
(10 rows)
并复制粘贴使用窗口函数的第一条语句:
and copy-pasted the first statement that uses a window function:
SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary;
但是,我收到以下错误消息:
However, I got the following error message:
ERROR: syntax error at or near "OVER"
LINE 1: SELECT depname, empno, salary, avg(salary) OVER (PARTITION B...
^
使用OVER子句的其他操作也没有奏效
我做错了什么?
Other efforts to use the OVER clause also didn't work.
What did I do wrong?
Thanks.
版本信息:
x86_64-pc-linux-gnu上的PostgreSQL 8.3.8,由GCC cc(GCC)4.2.4编译(Ubuntu 4.2 .4-1ubuntu3)
Version info: PostgreSQL 8.3.8 on x86_64-pc-linux-gnu, compiled by GCC cc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
推荐答案
您的版本是否可能不支持此功能?
Is it possible that this is not supported by your version?
来自 3.5。窗口函数您使用完全相同的函数
From 3.5. Window Functions you use the exact same function
以下示例显示了如何
将每个员工的薪水与
进行比较他或她的
部门的平均工资:
Here is an example that shows how to compare each employee's salary with the average salary in his or her department:
从经验中选择depname,empno,薪水,
avg(薪金)(按
depname分配);
SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary;
但它声明
PostgreSQL 8.4.1文档
PostgreSQL 8.4.1 Documentation
这篇关于错误:语法错误在“ OVER”处或附近。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!