I am having trouble making formatted dates group properly, I am thinking it might have to do with my left join, but I am not sure the path to take. Heres my query and results. For simplicity below I have not included the additional columns but note that utilizing distinct for the select, I don't believe is an option as it throws off my calculations.
When I use this:
SELECT DATE_FORMAT(posts.post_date, "%Y%m%d") AS 'Date', COUNT(*) AS 'Orders'
FROM wp_posts AS posts
LEFT JOIN wp_postmeta AS meta ON posts.ID = meta.post_id
WHERE meta.meta_key = '_order_total'
AND posts.post_type = 'shop_order'
AND posts.post_status = 'wc-completed'
I get this:
20170204
20170218
20170301
20170301
20170314
20170401
20170401
20170402
20170403
20170405
20170412
20170426
20170501
20170501
20170501
20170501
20170501
20170504
When I add the Group By, the results just drop down to a single line:
SELECT DATE_FORMAT(posts.post_date, "%Y%m%d") AS 'Date'
FROM wp_posts AS posts
LEFT JOIN wp_postmeta AS meta ON posts.ID = meta.post_id
WHERE meta.meta_key = '_order_total'
AND posts.post_type = 'shop_order'
AND posts.post_status = 'wc-completed'
GROUP BY 'Date'
I get this:
20170204
My desired output is:
20170204
20170218
20170301
20170314
20170401
20170402
20170403
20170405
20170412
20170426
20170501
20170504