Try to use the solution:
select id, ref, status, max(date)
from table
where status = 'P'
group by id, ref, status, date
union all
select id, ref, status, date
from table
where status = 'C'
with one query:
select *from
(select id, ref, status, max(date)
from table
where status = 'P'
group by id, ref, status, date
union all
select id, ref, status, date
from table
where status = 'C') RES