I am trying to use the a min and max functions on this case statements. What I want is that when the first case statement is true, I would like to return the min date and when the second case statement is true return the max date then group everything BY "Details"."PNumb"). I have tried it as shown below but getting syntax errors. any suggestions on where I might be going wrong?
(MIN(CASE WHEN "Details"."PNumb" = "Details"."PI" THEN "XX"."Date"
ELSE (CASE WHEN "Details"."PNumb" = "Details"."PI" AND "JOB"." Name" ="JOB"."Name"
THEN MAX("XX"."Date") END) END) BY "Details"."PNumb")