I need the help with this SQL to connect to a Oracle table.
The first select works perfectly
SELECT DISTINCT NUM_FACTURA,
NUM_RECEPCION,
SUM (CANTIDAD) AS CANTIDAD
FROM APPS.XXGC_GCC_RECEPCION_DISC_V XXGC_GCC_RECEPCION_DISC_V WHERE ( ARTÍCULO LIKE 'M8%' )
GROUP BY NUM_FACTURA, NUM_RECEPCION
And shows the following data:
First Select.jpg
But I need to sum the quantities and group by NUM_RECEPCION and using LISTAGG to put all the receptions in the same cell.
I create the following command:
SELECT NUM_FACTURA,
LISTAGG(NUM_RECEPCION, ' ') WITHIN GROUP (ORDER BY NUM_RECEPCION) AS NUM_RECEPCION,
SUM (CANTIDAD) AS CANTIDAD
FROM (SELECT DISTINCT NUM_FACTURA,
NUM_RECEPCION,
SUM (CANTIDAD) AS CANTIDAD
FROM APPS.XXGC_GCC_RECEPCION_DISC_V XXGC_GCC_RECEPCION_DISC_V WHERE ( ARTÍCULO LIKE 'M8%' )
GROUP BY NUM_FACTURA, NUM_RECEPCION)
GROUP BY NUM_FACTURA
The mistake
Mistake Second Select.jpg
When I tried to get the following data:
Result Expected.jpg
Thanks in advance.
Bookmarks