I'm trying to write a MySQL SELECT statement in PHP.
I have 2 tables, sales and sale_items.
sales has columns: sale_id, status
sale_items has columns: sale_id, date_added (DATETIME), quantity
I need to return the quantities from sale_items, over the last 12 months grouped by month and where the status of the corresponding row in sales is equal to 'completed' (as you can see, sales and sale_items can be joined by sale_id).
I have tried modifying both of the following to suit my needs, but with no luck:
MySQL monthly Sale of last 12 months including months with no Sale