Skip to content Skip to sidebar Skip to footer

Sql - Postgres - Return Maximum Value For Latest Date

This might be simple but I'm new to SQL and couldn't find how to do this exactly. I have following table: My requirement is follows: I need, for each Frequency (monthly & week

Solution 1:

you could use a join with a subquery for get max date and then the max version

select s.Dim, s.Frequency, s.Date, max(s.Version)
from sample_tbl s 
inner ( 
SELECT Dim, Frequency, max(Date) as max_date
FROM   sample_tbl 
group by Dim, Frequency
) t on t.Dim = s.Dim, t.Frequency = s.Frequency t.max_date = s.Date 
GROUP BY s.Dim, s.Frequency, s.Date ;

Post a Comment for "Sql - Postgres - Return Maximum Value For Latest Date"