You will need a date table to group against. This is pretty easy in MSSQL using CTE, for example this - I'm not sure if MySQL has something like this? Otherwise, you will need to create a hard table as one exercise
EDIT: Try:
SELECT COUNT(pp.subscribe_date) AS counter, dl.date, MIN(pp.recur) FROM date_lookup dl LEFT OUTER JOIN paypal pp on (pp.subscribe_date = dl.date AND pp.recur ='monthly') WHERE dl.date >= '2010-07-16' and dl.date <= '2010-07-23' GROUP BY dl.date ORDER BY dl.date
- The subject of the request should be changed to the date_lookup table (the order of the left external connection becomes important)
- Count (*) will not work, because the "date" record always exists - you need to read something in the PayPay table
- pp.recur = 'month' is now a join condition, not a filter due to LOJ
Finally, showing pp.recur in the select list will not work.
I used aggregate, but MIN (pp.recur) will return null if there are no PayPal entries
What can you do when you parameterize your query, just repeat the filter like Recur? Again, plz justifies the MSSQL syntax
SELECT COUNT(pp.subscribe_date) AS counter, dl.date, @ppRecur FROM date_lookup dl LEFT OUTER JOIN paypal pp on (pp.subscribe_date = dl.date AND pp.recur =@ppRecur ) WHERE dl.date >= @DateFrom and dl.date <= @DateTo GROUP BY dl.date ORDER BY dl.date
source share