Q:

ORA-00920: invalid relational operator when using aggregate inside sub query

I am writing a simple query in Oracle,
SELECT CN.MyColumn1,
       SUM(CN.MyColumn2 - CN.MyColumn3 + CN.MyColumn4),
       (CASE 
          WHEN EXISTS (
             SELECT 't' 
             FROM Table1 CN2 
             WHERE CN2.MyColumn1  = CN.MyColumn1 
               AND CN2.MyColumn5= 0 
               AND (CN2.MyColumn2- CN2.MyColumn3+ CN2.MyColumn4) >= 
                SUM(CN.MyColumn2- CN.MyColumn3 + CN.MyColumn4) * 0.5)
            THEN 'Yes' 
          ELSE 'No' 
       END)
FROM Table1 CN 
GROUP BY CN.MyColumn1 
HAVING SUM (CN.MyColumn2- CN.MyColumn3 + CN.MyColumn4) < 6;

But I am getting 

SQL Error [920] [42000]: ORA-00920: invalid relational operator

A:

The problem stems from 
SUM aggregation being used in SUM(CN.MyColumn2- CN.MyColumn3 + CN.MyColumn4) * 0.5) 
which needs to be used within HAVING clause. You may try to use the one below :
SELECT CN.MyColumn1,
       SUM(CN.MyColumn2 - CN.MyColumn3 + CN.MyColumn4),
       (CASE 
          WHEN EXISTS (
             SELECT 't' 
             FROM Table1 CN2 
             WHERE CN2.MyColumn1  = CN.MyColumn1 
               AND CN2.MyColumn5= 0 
            HAVING (CN2.MyColumn2- CN2.MyColumn3+ CN2.MyColumn4) >= 
                SUM(CN.MyColumn2- CN.MyColumn3 + CN.MyColumn4) * 0.5)
          THEN 'Yes' 
          ELSE 'No' 
       END)
FROM Table1 CN 
GROUP BY CN.MyColumn1 
HAVING SUM (CN.MyColumn2- CN.MyColumn3 + CN.MyColumn4) < 6;

Demo

