I am trying to join multiple tables using an oracle sql query and showing the sum of each country from the table "Arab_countries" which has a transaction in the table "CTTRANS"
I am trying to show the sum of transactions by each country. However, the countries that have no transactions are not shown in the output
For example. "AAA" has no transactions, but its not showing in the results of my query. I need it to show as 0
SELECT ARAB_COUNTRIES.COMP_CODE, ARAB_COUNTRIES.COUNTRY_CODE, ARAB_COUNTRIES.SS_CODE, ARAB_COUNTRIES.BRIEF_DESC_ARAB, ARAB_COUNTRIES.LONG_DESC_ENG, ARAB_COUNTRIES.LONG_DESC_ARAB,
SUM(CTTRANS.CV_AMOUNT)
FROM ARAB_COUNTRIES
LEFT JOIN CUST
ON (ARAB_COUNTRIES.COMP_CODE = CUST.COMP_CODE)
AND (ARAB_COUNTRIES.COUNTRY_CODE = CUST.NATION_CODE)
LEFT JOIN CTTRANS
ON (CTTRANS.COMP_CODE = CUST.COMP_CODE )
AND (CTTRANS.TRS_AC_CUST = CUST.CUST_NO)
WHERE
CTTRANS.STATUS = 'P' AND CTTRANS.TRX_TYPE IN (201,15,35,586)
AND TRUNC(CTTRANS.TRS_DATE) BETWEEN '01-APR-20' AND '30-JUN-20'
AND ARAB_COUNTRIES.COUNTRY_CODE <> 999
GROUP BY ARAB_COUNTRIES.COMP_CODE, ARAB_COUNTRIES.COUNTRY_CODE, ARAB_COUNTRIES.SS_CODE, ARAB_COUNTRIES.BRIEF_DESC_ARAB, ARAB_COUNTRIES.LONG_DESC_ENG, ARAB_COUNTRIES.LONG_DESC_ARAB
ORDER BY ARAB_COUNTRIES.COUNTRY_CODE;