From: | Lutz Horn <lutz(dot)horn(at)posteo(dot)de> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Please advice on a query |
Date: | 2017-11-14 20:11:57 |
Message-ID: | 5440f7e2-5885-306f-0acc-ea69e039d98b@posteo.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
Hi,
Am 14.11.17 um 18:19 schrieb Efraín Déctor:
> You could use a window function:
> https://www.postgresql.org/docs/current/static/functions-window.html
Like this:
lutz=> \d dates
Table "pg_temp_3.dates"
Column | Type | Modifiers
--------+------+-----------
d | date |
lutz=> select * from dates;
d
------------
2017-01-01
2017-01-01
2017-10-15
2017-10-15
2017-10-15
2017-11-09
2017-11-09
2017-11-09
2017-11-09
(9 rows)
lutz=> select d from (
select d, rank() over (order by d desc) as r from dates
) as sq
where r = 1;
d
------------
2017-11-09
2017-11-09
2017-11-09
2017-11-09
(4 rows)
Regards
Lutz
From | Date | Subject | |
---|---|---|---|
Next Message | JORGE MALDONADO | 2017-11-15 19:14:01 | How to get n records from parent table and their children |
Previous Message | Efraín Déctor | 2017-11-14 19:00:04 | Re: Strange problem with autovacuum |