错误:语法错误在“OVER”或附近

时间:2022-06-01 12:35:16

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:

我是SQL语言和PostgreSQL的新手。我熟悉这门语言并且正在学习PostgreSQL教程,直到我遇到关于窗口函数的一章(链接文本。我创建了完全相同的表'empsalary',如示例中所示:

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...
                                                   ^

Other efforts to use the OVER clause also didn't work. What did I do wrong?
Thanks.

使用OVER子句的其他努力也不起作用。我做错了什么?谢谢。

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)

版本信息:x86_64-pc-linux-gnu上的PostgreSQL 8.3.8,由GCC cc(GCC)4.2.4编译(Ubuntu 4.2.4-1ubuntu3)

1 个解决方案

#1


4  

Is it possible that this is not supported by your version?

您的版本是否可能不支持此功能?

From 3.5. Window Functions you use the exact same function

从3.5开始。窗口函数使用完全相同的函数

Here is an example that shows how to compare each employee's salary with the average salary in his or her department:

这是一个示例,显示如何将每个员工的工资与其部门的平均工资进行比较:

SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary;

SELECT depname,empno,salary,avg(salary)OVER(PARTITION BY depname)FROM empsalary;

but it states

但它说

PostgreSQL 8.4.1 Documentation

PostgreSQL 8.4.1文档

#1


4  

Is it possible that this is not supported by your version?

您的版本是否可能不支持此功能?

From 3.5. Window Functions you use the exact same function

从3.5开始。窗口函数使用完全相同的函数

Here is an example that shows how to compare each employee's salary with the average salary in his or her department:

这是一个示例,显示如何将每个员工的工资与其部门的平均工资进行比较:

SELECT depname, empno, salary, avg(salary) OVER (PARTITION BY depname) FROM empsalary;

SELECT depname,empno,salary,avg(salary)OVER(PARTITION BY depname)FROM empsalary;

but it states

但它说

PostgreSQL 8.4.1 Documentation

PostgreSQL 8.4.1文档