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 1ozKCx-0002j7-Cm for pgsql-sql@arkaria.postgresql.org; Sun, 27 Nov 2022 16:08:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ozKCv-0001g9-Tu for pgsql-sql@arkaria.postgresql.org; Sun, 27 Nov 2022 16:08:41 +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 1ozKCv-0001g0-Ix for pgsql-sql@lists.postgresql.org; Sun, 27 Nov 2022 16:08:41 +0000 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1ozKCs-0004xR-6X for pgsql-sql@lists.postgresql.org; Sun, 27 Nov 2022 16:08:40 +0000 Received: by mail-pf1-x432.google.com with SMTP id o1so3765834pfp.12 for ; Sun, 27 Nov 2022 08:08:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Ge1A31zWQr57anJwcwDOMvoyPh1kUeyf7rS/EI/5kDc=; b=nNWKYB1pdl/gz5IMWzsh2DPe7cTaCYVWkd/MPS71YrK+izmLJkHXr40drj4+hZL9Yd HQf/eYtxFkRG3pu6CWk2I2LOmoF/b7qSm1W9Qg7AUf/PtWQq4pSHOkToKG61qWQQCPMl kDYpPh62MD6mCfdk2X5XH5MMjpUtiif3AZ9BOSiuj9O3WWk9F2YE5HvPhGvDz0uPO5qu oOAIm6gAy2R6IRVgT+hnjjJJiwC+qZQUzyJyDW1g6kEavLb8JZ/NAHgTQB6nymu+dIkU 2SuR2vVBV1OfQuvp7dJWSqylDU/jM5LvV67m+baVfmozTzm/5uhMY6qAKPbpHfZY6dOt L6ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:to:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Ge1A31zWQr57anJwcwDOMvoyPh1kUeyf7rS/EI/5kDc=; b=N7em2lKzzv3S9s8MNqYKXVhWlIBOHyWLe91lO0nA/k7bn/YmuiZJiPO9vIcURBL/yK AneXmFCfa5i0cNnBG/bAHZWo06bQ5jYguIrpX5oNYsvLFy+hlt0CAFFqDlbJslsS9nps 6yaM13rMopPnU3k4yKGrpoKnJN34MXlhJDUWGBT3Tisu+jqgqvr9kT8Qa/XezMGlfhaA KXRSFcg+Njh3AvNQ+QMfi3gX4I2tbKm8DeNswAB/qSGMcwXrRSA667nb2e28SSv5N4LQ FlnrJjOnjrvjqv/ho6stDogsdQz040sXNMxavxaabXJ6kGj7I7SeAgyKEcSpmniSKtjb P3vg== X-Gm-Message-State: ANoB5pmvGMvLnvbqEWrtWJoHE8eFHYBz/1P6kkhYQoJ3IWXl4M6hAOAz oqMa2YW4+9Od/7WNfoiR14Mgx0dHNRI= X-Google-Smtp-Source: AA0mqf7h6gqMIgPe7tt6lz0/ndALvM/dmPcPBW6jlU0nEEsOcsoRgxWhOCPfDuo7lzbtupmurp4b4A== X-Received: by 2002:a63:1e62:0:b0:46b:3acb:77b2 with SMTP id p34-20020a631e62000000b0046b3acb77b2mr22713874pgm.560.1669565316164; Sun, 27 Nov 2022 08:08:36 -0800 (PST) Received: from [10.0.2.15] ([122.163.232.215]) by smtp.gmail.com with ESMTPSA id d185-20020a621dc2000000b0056bf29c9ba3sm6534976pfd.146.2022.11.27.08.08.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 27 Nov 2022 08:08:35 -0800 (PST) Message-ID: <7f9f9b1d-b612-d0bd-4674-cfb5a8b2d343@gmail.com> Date: Sun, 27 Nov 2022 21:38:33 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Content-Language: en-US To: pgsql-sql@lists.postgresql.org From: Ankit Kumar Pandey Subject: [QUESTION] Window function with partition by and order by Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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