There is a trick to this.
The issue is that any groupings you apply will not effect the sum. You need a
Common Table Expressions(CTE)[
^].
Read up on it because they are so powerful
So, your query might look like this:
WITH myCTE1 as (
SELECT Id, Status, Number
From table
where Status = 'P'),
myCTE2 as (
Select t.Id, t.Status, t.Number
From table t
where t.Status = 'F'
AND NOT EXISTS (SELECT * FROM myCTE1 WHERE Id = t.Id)
UNION SELECT Id, Status, Number
FROM myCTE1)
SELECT sum(Number), Status FROM myCTE2 GROUP BY Status