It happens to me that I have to do an exercise in which I must generate two columns based on an aggregation function (sum) and each one is according to a code that this table shares in common and another in which there are only two records (1 that would correspond to "Subscription" and 2 to "Redemptions")
SELECT
UPPER(TO_CHAR(CLI.NUMRUN,'09G999G999') || '-' || CLI.DVRUN) AS "RUN CLIENTE",
INITCAP(CLI.PNOMBRE || ' ' || CLI.SNOMBRE || ' ' || CLI.APPATERNO || ' ' || CLI.APMATERNO) AS "NOMBRE CLIENTE",
SUM(MO.MONTO_MOVIMIENTO) AS "ABONOS",
SUM(MO.MONTO_MOVIMIENTO) AS "RESCATES"
FROM
CLIENTE CLI JOIN MOVIMIENTO MO
ON (CLI.NRO_CLIENTE = MO.NRO_CLIENTE)
GROUP BY
CLI.NUMRUN,
CLI.DVRUN,
CLI.PNOMBRE,
CLI.SNOMBRE,
CLI.APPATERNO,
CLI.APMATERNO;
What I want to do is place a WHERE clause for "BONDS" AND "RESCATES" where one adds only those of code X while the other only those of code Y.
It would help you to use
case...when
: