subqueries with multiple date results
I am building a query that shows the number of orders received, on each date within a range of dates
Wanted: a 2nd column of orders that were shipped in full on the same day they were received.
this is what I have so far, and the results of orders in are fine, but for the shipment column, i'm getting the same total for each day, the number of shipments encompassed by the the entire range. I know I need to somehow join the subquery to the main query, but I just can't work it out.
I tried it with an if in relation to the completed date, without using a subquery, but because I HAVE to have the "does not meet condition" branch of the IF, which i tried to make zero, I was not getting reliable results.
If there is a better way than using a subquery, I'm open to it.
Thanks in Advance!
snip of results
2018-12-01 88 1640
2018-12-02 91 1640
2018-12-03 99 1640
2018-12-04 116 1640
2018-12-05 96 1640
Any help would be greatly appreciated. I'm sure I'm trying to make it be harder than it is!
I am building a query that shows the number of orders received, on each date within a range of dates
Wanted: a 2nd column of orders that were shipped in full on the same day they were received.
this is what I have so far, and the results of orders in are fine, but for the shipment column, i'm getting the same total for each day, the number of shipments encompassed by the the entire range. I know I need to somehow join the subquery to the main query, but I just can't work it out.
I tried it with an if in relation to the completed date, without using a subquery, but because I HAVE to have the "does not meet condition" branch of the IF, which i tried to make zero, I was not getting reliable results.
If there is a better way than using a subquery, I'm open to it.
Thanks in Advance!
Code:
SELECT
DATE(order_date) AS 'date',
COUNT(o.id),
(SELECT
COUNT(id)
FROM
orders #edited table name from base_orders to orders
WHERE
DATE(completed) BETWEEN '2018-12-01' AND '2018-12-13') AS 'shipped_complete'
FROM
orders o
WHERE
DATE(o.order_date) BETWEEN '2018-12-01' AND '2018-12-13'
GROUP BY DATE(o.order_date)
snip of results
2018-12-01 88 1640
2018-12-02 91 1640
2018-12-03 99 1640
2018-12-04 116 1640
2018-12-05 96 1640
Any help would be greatly appreciated. I'm sure I'm trying to make it be harder than it is!