Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozKWj-0003ht-Me for pgsql-sql@arkaria.postgresql.org; Sun, 27 Nov 2022 16:29:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ozKVk-0006SW-HN for pgsql-sql@arkaria.postgresql.org; Sun, 27 Nov 2022 16:28:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozKVk-0006SN-8Q for pgsql-sql@lists.postgresql.org; Sun, 27 Nov 2022 16:28:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozKVh-00056b-T2 for pgsql-sql@lists.postgresql.org; Sun, 27 Nov 2022 16:28:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2ARGS4IB355605; Sun, 27 Nov 2022 11:28:04 -0500 From: Tom Lane To: Ankit Kumar Pandey cc: pgsql-sql@lists.postgresql.org Subject: Re: [QUESTION] Window function with partition by and order by In-reply-to: <7f9f9b1d-b612-d0bd-4674-cfb5a8b2d343@gmail.com> References: <7f9f9b1d-b612-d0bd-4674-cfb5a8b2d343@gmail.com> Comments: In-reply-to Ankit Kumar Pandey message dated "Sun, 27 Nov 2022 21:38:33 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <355603.1669566484.1@sss.pgh.pa.us> Date: Sun, 27 Nov 2022 11:28:04 -0500 Message-ID: <355604.1669566484@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Ankit Kumar Pandey writes: > 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? https://www.postgresql.org/docs/current/tutorial-window.html particularly: By default, if ORDER BY is supplied then the frame consists of all rows from the start of the partition up through the current row, plus any following rows that are equal to the current row according to the ORDER BY clause. regards, tom lane