This is my QUERY in SQLite. Currently following the Google Data Analytics Certificate.
SELECT
Warehouse.warehouse_id,
Warehouse.state || ': ' || Warehouse.warehouse_alias AS warehouse_name,
COUNT(Orders.order_id) AS number_of_orders,
(SELECT
COUNT(*)
FROM Warehouse_Orders Orders)
AS total_orders,
CASE
WHEN COUNT(Orders.order_id)/(SELECT COUNT(*) FROM Warehouse_Orders Orders) <= 0.20
THEN 'Fulfilled 0-20% of Orders'
WHEN COUNT(Orders.order_id)/(SELECT COUNT(*) FROM Warehouse_Orders Orders) > 0.20
AND COUNT(Orders.order_id)/(SELECT COUNT(*) FROM Warehouse_Orders Orders) <= 0.60
THEN 'Fulfilled 21-60% of Orders'
ELSE 'Fulfilled more than 60% of Orders'
END AS fulfillment_summary
FROM Warehouse_Stats Warehouse
LEFT JOIN Warehouse_Orders Orders
ON Warehouse.warehouse_id = Orders.warehouse_id
GROUP BY
Warehouse.warehouse_id,
warehouse_name
HAVING
COUNT(Orders.order_id) >1
I realise it is a problem with my CASE
- The Orders.order_id is fine as the COUNT returns the number of orders per warehouse. -Yet the total is not working "SELECT COUNT(*) FROM Warehouse_Orders Orders"
How do I find the total?
I've tried, to take my SQL query apart and try different methods but I'm struggling to return the total.