Answer the question
In order to leave comments, you need to log in
How to convince PostgreSQL to use an index?
There is a table like
label | timestamp
AAA | 1408937820000
AAA | 1408937880000
AAA | 1408937940000
AAA | 1408938000000
BBB | 1408938120000
BBB | 1408938180000
BBB | 1408938240000
BBB | 1408938300000
BBB | 1408938360000
(label, timestamp)
. There is also a set of columns with numbers, but they are used as ballast and do not participate in the selection. SELECT
label, max(timestamp) as latest
FROM
table
GROUP BY label;
SELECT
label, max(timestamp) as latest
FROM
table
WHERE label = 'AAA';
Answer the question
In order to leave comments, you need to log in
I have a table that already has a list of unique labels
select label, latest_stamp from labelstable lateral (
select timestamp as latest_stamp from tablename where tablename.label = labeltable.label
order by timestamp desc limit 1
) l
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question