开发者

ERROR: syntax error at or near "OVER"

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

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

Thanks.

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?

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:

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

but it states

PostgreSQL 8.4.1 Documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜