Skip to content
Advertisement

Select row where latest quarter and year In POSTGRESQL

I need help with my issue here . I need to select rows where quarter and year are latest . Here is example of my table

Risk Master table named HD_Risk_Master:-

Another table that join with HD_Risk_Master table named HD_Case_Resolution 1:M

Expected Result

My result of query , no HDS-OP3 and HDS-OP4 in my query which i realised the max year is 2022 and the max quarter is Q4 which in 2021 . It supposed to read year 2022 and quarter 1(in year 2022)

Here is my attempt query which resulted as above ;-

Hope it’s help and sorry for my bad explaination and grammar .

Advertisement

Answer

Join master with a derived table which orders the rows from details

db<>fiddle

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement