Here's the logic I am atempting to apply
Have a base_orders table. It contains order_date and completed (shipped)
The first part is I needed to know the number of orders that were received and shipped out on the same day, for a range of days (a week for example)
Someone was nice enough to help me out with that last week, and now I need to extend it one more step
There's a separate table - base_order_shipments - that has ALL the shipment info. I'd like to add a column that shows ALL shipments for the same days within the date range. These would be orders, or partial orders that were NOT able to be shipped the day they were received, and I would expect the shipments from the outer join to be within those numbers as well - no need to exclude them). So generally the total shipments for any given day should be higher than the orders received and shipped on the same given day.
So the first part works (I've got the offending statements commented out here, when I un-comment those two lines, I get results across ALL time (for the past three years.)
I know this is going to be a subquery and that I have to join the grouped results of the inner join to the outer join, but I just cannot work out how to do it with my tables.
Any enlightenment will be greatly appreciated! Thanks for reading!
Have a base_orders table. It contains order_date and completed (shipped)
The first part is I needed to know the number of orders that were received and shipped out on the same day, for a range of days (a week for example)
Someone was nice enough to help me out with that last week, and now I need to extend it one more step
There's a separate table - base_order_shipments - that has ALL the shipment info. I'd like to add a column that shows ALL shipments for the same days within the date range. These would be orders, or partial orders that were NOT able to be shipped the day they were received, and I would expect the shipments from the outer join to be within those numbers as well - no need to exclude them). So generally the total shipments for any given day should be higher than the orders received and shipped on the same given day.
So the first part works (I've got the offending statements commented out here, when I un-comment those two lines, I get results across ALL time (for the past three years.)
I know this is going to be a subquery and that I have to join the grouped results of the inner join to the outer join, but I just cannot work out how to do it with my tables.
Any enlightenment will be greatly appreciated! Thanks for reading!
Code:
select
date(bo.order_date) as 'date',
count(bo.id) as 'orders received',
sum(date(bo.order_date) = date(bo.completed)) as 'shipped_complete'
#sum(date(bos.completed) = date(bo.completed)) as 'total shipments'
from base_orders bo
#join base_order_shipments bos on date(bos.completed) = date(bo.completed)
where date(bo.order_date) between '2018-12-01' and '2018-12-13'
group by date(order_date)