funciones ventana cual criterio emplea el order by para 'filtral'

From: Hellmuth Vargas <hivs77(at)gmail(dot)com>
To: Lista Postgres ES <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: funciones ventana cual criterio emplea el order by para 'filtral'
Date: 2018-04-04 20:33:46
Message-ID: CAN3Qy4oFhxBZjSYJfLabno13Lrduz_zmDMW37Fomadm4Pi=PBA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Hola Lista

Tiempo sin hablarmos!! :-)

Estaba leyendo el siguiente articulo:

https://www.cybertec-postgresql.com/en/advanced-sql-why-first_value-and-last_value-are-no-bugs/

y de este genere la siguiente consulta

SELECT *,
array_agg(x) OVER () as todos,
array_agg(x) OVER (ORDER BY x) as order_asc,
array_agg(x) OVER (ORDER BY x DESC) as order_desc,
last_value(x) OVER (ORDER BY x)
FROM generate_series(1, 5) AS x order by 1;

cuyos resultados son:

x | todos | order_asc | order_desc | last_value
---+-------------+-------------+-------------+------------
1 | {1,2,3,4,5} | {1} | {5,4,3,2,1} | 1
2 | {1,2,3,4,5} | {1,2} | {5,4,3,2} | 2
3 | {1,2,3,4,5} | {1,2,3} | {5,4,3} | 3
4 | {1,2,3,4,5} | {1,2,3,4} | {5,4} | 4
5 | {1,2,3,4,5} | {1,2,3,4,5} | {5} | 5
(5 rows)

Y la verdad no entiendo la lógica del 'filtrado' que hace el order by
(ASC/DESC). Gracias Lista

--
Cordialmente,

Ing. Hellmuth I. Vargas S.

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2018-04-04 20:55:32 Re: funciones ventana cual criterio emplea el order by para 'filtral'
Previous Message jvenegasperu . 2018-03-27 16:16:49 Funciones Financieras Postgres