As an additional input, although it is not associated with this stream, you can also aggregate your case statements without mentioning this in the group by section.
SELECT WORK_ORDER_NUMBER, SUM (CASE WHEN STOCK_CODE LIKE 'xxxx' THEN STOCK_QUANTITY ELSE 0 END) AS TOTAL From the GROUP BY WORK_ORDER_NUMBER table;
Please JK.
source share