I cannot get my head around this one, I have a "funcky" subquery:
SELECT
"Requisition_ID",
"Candidate_ID",
"Application_Date",
CA."Process_of_Activity",
CA."Activity",
"Completed_on",
add_minutes(cast("Completed_on" as timestamp),STAT."Rank") as "Current Completed on"
FROM CA
left join STATUS as STAT
on CA."Process_of_Activity" = STAT."Process_of_Activity" and CA."Activity" = STAT."Activity"
GROUP BY "Requisition_ID","Candidate_ID","Application_Date", STAT."Rank", CA."Process_of_Activity", CA."Activity", "Completed_on";
This basically gives me a table with 7 columns. I need a result with the same 7 columns GROUPED by the first 3 where the last column is Max. For example. if the original subquery shows me:
Requisition_ID Candidate_ID Application_Date Process_of_Activity Activity Completed_on Current Completed on
123 555 16/12/2015 To be Rejected Rejection 08/03/2016 08/03/2016 00:29
123 555 16/12/2015 To be Rejected Letter:Rejection 08/03/2016 08/03/2016 00:00
123 555 16/12/2015 Application Entry Questionnaire 16/12/2015 16/12/2015 00:00
123 555 16/12/2015 Application Entry Application Entr 08/03/2016 08/03/2016 00:01
in this case I would only want to see the first line of this sample ... so I want to group by "Requisition_ID", "Candidate_ID", "Application_Date"
but also see what the values are for: CA."Process_of_Activity", CA."Activity", "Completed_on"
where "Current Completed on" is max. but of course much more Requisitions, candidates and Application dates in the system. I am using dashDB.