I have payment
data table (MySQL) to record all the payments. I want to group all the payments by date. Actually I want to group them by month to analyze what's the income they get for a specific month. If there are no payments in a specific month, I need that as 0.
Here is my SQL code for that.
SELECT SUM(p.sub_total) as sold_income , month(p.invoice_date) as income_month ,MONTHNAME(p.invoice_date) as month_name, YEAR(p.invoice_date) as income_year FROM payment p where (p.invoice_date BETWEEN '2018-01-01' AND '2018-08-01') GROUP BY DATE_FORMAT(p.invoice_date, '%Y%m')
From this code, I get the following output :
I searched between '2018-01-01' AND '2018-08-01'. So there should be 7 months and 7 results. If there are no payments for month no 1 (January) , I want the sold_income = 0
;
How do I do that ? Please help me....