public inbox for [email protected]  
help / color / mirror / Atom feed
From: Ankit Kumar Pandey <[email protected]>
To: [email protected]
Subject: [QUESTION] Window function with partition by and order by
Date: Sun, 27 Nov 2022 21:38:33 +0530
Message-ID: <[email protected]> (raw)

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






view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: [QUESTION] Window function with partition by and order by
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox