Hier nochmal ein neuer Versuch...
SQL-Code:
SELECT datum,
SUM(CASE WHEN typ_id = 1 THEN wert ELSE 0 END)
+SUM(CASE WHEN typ_id = 2 THEN wert ELSE 0 END)
-SUM(CASE WHEN typ_id = 3 THEN wert ELSE 0 END)
-SUM(CASE WHEN typ_id = 4 THEN wert ELSE 0 END)
+SUM(CASE WHEN typ_id = 5 THEN wert ELSE 0 END)
- CASE WHEN duration IN (15, 20) THEN SUM(CASE WHEN typ_id = 6 THEN wert ELSE 0 END) ELSE 0 END
- CASE WHEN duration = 20 THEN SUM(CASE WHEN typ_id = 7 THEN wert ELSE 0 END) ELSE 0 END AS wert
FROM element e, (SELECT DISTINCT duration
FROM config
WHERE domain = :domain) c
WHERE datum BETWEEN :von AND :bis
AND pilot_id = :pilot_id
GROUP BY datum