Trying to find 3 separate counts within one column of a table, each with separate WHERE clauses. I've got 2 tables in the query, so one join. Thought this looked correct but it will not run:
SELECT stores.caption,
COUNT ( WHEN tasks.created_at BETWEEN '2019-04-01' AND '2019-04-30' AND tasks.deleted_at IS NULL) AS TaskTotal ,
COUNT ( WHEN tasks.created_at BETWEEN '2019-04-01' AND '2019-04-30' AND tasks.deleted_at IS NULL AND tasks.completed_at IS NULL) AS TaskOutstanding,
COUNT (
WHEN tasks.created_at BETWEEN '2019-04-01' AND '2019-04-30'
AND tasks.deleted_at IS NULL
AND tasks.completed_at IS NULL
AND tasks.deadline < '2019-05-16') AS TaskOverdue
SELECT stores.caption,
COUNT (
WHEN tasks.created_at BETWEEN '2019-04-01' AND '2019-04-30'
AND tasks.deleted_at IS NULL)
AS TaskTotal ,
COUNT (
WHEN tasks.created_at BETWEEN '2019-04-01' AND '2019-04-30'
AND tasks.deleted_at IS NULL
AND tasks.completed_at IS NULL) AS TaskOutstanding,
COUNT (
WHEN tasks.created_at BETWEEN '2019-04-01' AND '2019-04-30'
AND tasks.deleted_at IS NULL
AND tasks.completed_at IS NULL
AND tasks.deadline < '2019-05-16') AS TaskOverdue
FROM tasks
FULL JOIN stores ON tasks.store_id=stores.id
GROUP BY stores.caption;