I am trying to create a SELECT statement that selects all (*) the fields from a table that meet the following:
1 row for each DISTINCT( client_id, fileno, ppyear) combination, but only including the MAX(ppyear)
Based on what I have read, I believe I need to do a SELECT with SUBGROUP like
SELECT * FROM ppropdb
where concat(ppropdb.ppyear,ppropdb.fileno)
IN (SUBGROUPQUERY)
I have tried to build a subquery to select them:
SELECT ppropdb.ppyear, ppropdb.client_id, ppropdb.fileno
FROM ppropdb
GROUP BY concat(ppropdb.ppyear,ppropdb.fileno)
ORDER BY client_id,fileno,ppyear
but this does not return the MAX(ppyear) rows
2
Answers
how about using a windowing function such as rownum select the max ppyear and group it by client_id, fileno. then select the columns where your rownum = 1 someting like below