Search Postgresql Archives

Re: FIRST_VALUE: need to group by argument?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 24, 2016 at 12:12 PM, Manuel Gómez <targen@xxxxxxxxx> wrote:
On Tue, May 24, 2016 at 8:50 AM, David G. Johnston
<david.g.johnston@xxxxxxxxx> wrote:
> SELECT x, sum(i), sum(sum(i)) OVER (PARTITION BY x) FROM ( VALUES (a,1),
> (a,2), (b,3) ) val (x,i) GROUP BY x
> yields
> a, 3, 6
> b, 3, 6

Thank you for this enlightening explanation!  I was, however, very
confused from this specific bit, so I tested it and indeed there must
have been a typo:

postgres=# SELECT x, sum(i), sum(sum(i)) OVER (PARTITION BY x) FROM
(VALUES ('a', 1), ('a', 2), ('b', 3)) val (x,i) GROUP BY x;
 x | sum | sum
---+-----+-----
 a |   3 |   3
 b |   3 |   3
(2 rows)

​Yes, that was me being careless.  The partition in the window makes the sum(sum(i)) evaluate to 3

David J.​
 


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux