[Solved] SQL, SUM + CASE [closed]


Never use commas in the FROM clause. Always use proper, explicit JOIN syntax.

Then, you cannot nest aggregation functions, so this should be sufficient:

SELECT o.ID_DOSSIER,
       SUM(CASE WHEN ID_TYPE IN ('0', '1') THEN TTL * -1
                WHEN ID_TYPE IN ('2', '3') THEN TTL
           END)
FROM ope o JOIN
     actor a
     ON o.ID_ACTION = a.ID_ACTION
GROUP BY o.ID_DOSSIER

0

solved SQL, SUM + CASE [closed]