Hi Please find the logic below:
SELECT "0PLANT", "0MATERIAL",
(case when sum(case when "0MOVETYPE" = 602 then 1 else 0 end) > 0
then max(case when "0MOVETYPE" = 602 then "0PSTNG_DATE" end)
when sum(case when "0MOVETYPE" = 601 then 1 else 0 end) > 0
then max(case when "0MOVETYPE" = 601 then "0PSTNG_DATE" end)
when sum(case when "0MOVETYPE" = 102 then 1 else 0 end) > 0
then max(case when "0MOVETYPE" = 102 then "0PSTNG_DATE" end)
when sum(case when "0MOVETYPE" = 101 then 1 else 0 end) > 0
then max(case when "0MOVETYPE" = 101 then "0PSTNG_DATE" end)
end) as Last_Sales_Date
\FROM "NM1"."PUBLIC"."IZDSO_DMR" Table__1
Group By "0MATERIAL", "0PLANT"
Thanks,
G Sampath Kumar