[QUESTION] Window function with partition by and order by - Mailing list pgsql-sql

From Ankit Kumar Pandey
Subject [QUESTION] Window function with partition by and order by
Date
Msg-id 7f9f9b1d-b612-d0bd-4674-cfb5a8b2d343@gmail.com
Whole thread Raw
Responses Re: [QUESTION] Window function with partition by and order by  (William Alves Da Silva <william_silva@unochapeco.edu.br>)
Re: [QUESTION] Window function with partition by and order by  (Samed YILDIRIM <samed@reddoc.net>)
Re: [QUESTION] Window function with partition by and order by  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hello,

While looking at aggregates in window function, I found something 
unusual and would be glad I could get some clarification.

Consider following table (mytable):

id, name

1, A

1, A

2, B

3, A

1, A


select *, avg(id) over (partition by name, order by id) from mytable;

Output:

id, name, avg

1, A, 1

1, A, 1

1, A, 1

3, A, 1.5

2, B, 2


Question is: Average of id for partition name (A) should be 6/4 = 1.5 
for all rows in that partition but this result is seen only at the last 
one row in partition (A). Am I missing here something?


Thanks


-- 
Regards,
Ankit Kumar Pandey




pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: access sub elements using any()
Next
From: William Alves Da Silva
Date:
Subject: Re: [QUESTION] Window function with partition by and order by