I would like to know if it's possible to SUM if a field has a specific value otherwise take only the MIN (just one value of the aggregated records)
I tried something like that but it's syntactically not correct, so I'm looking for an alternative to achieve this:
SELECT FROM ZCDS
FIELDS ZCDS~networkID as networkID,
ZCDS~assignment as assignment,
CASE
WHEN ZCDS~assignment = 'N'
THEN MIN( ZCDS~amount )
ELSE SUM( ZCDS~amount )
END as amount
GROUP BY ZCDS~networkID, ZCDS~assignment
INTO TABLE @DATA(result).
Maybe there is a way to determine if the SUM is already not 0, then use the case to stop adding more amount. But I don't know how to access the intermediate value of the SUM in a CASE, probably it's not possible as well
Expected input:
+----+-----------+------------+--------+
| ID | NetworkID | Assignment | Amount |
+----+-----------+------------+--------+
| 1 | D/01 | N | 7 |
| 2 | D/01 | N | 5 |
| 3 | D/01 | U | 15 |
| 4 | D/01 | U | 11 |
| 5 | D/02 | N | 40 |
| 6 | D/02 | N | 42 |
+----+-----------+------------+--------+
Expected output:
+-----------+------------+--------+
| NetworkID | Assignment | Amount |
+-----------+------------+--------+
| D/01 | N | 5 |
| D/01 | U | 26 |
| D/02 | N | 40 |
+-----------+------------+--------+