SELECT b.PERIOD, a.DIRECCION, SUM(AMOUNT) AS TOTAL FROM APLI1 a FULL JOIN tablaperiodos b ON a.period=b.period GROUP BY PERIOD, DIRECCION