Извините за основной вопрос:
select `plans`.`name`, `A`.`subscription_id`, `A`.`amount`,
`A`.`created_date`, `A`.`end_date`,
`A`.`subscription_status`, `users`.`email`, `A`.`plan_id`,
`A`.`user_id`, `usage`.`created_at` as `usagedate`,
COUNT(usage.id) as used_count
from `subscriptions` A
left join `users` on `users`.`id` = `A`.`user_id`
left join `plans` on `A`.`plan_id` = `plans`.`Id`
left join `usage` on `A`.`user_id` = `usage`.`user_id`
where `usage`.`created_at` between A.created_at and A.end_date
group by `A`.`plan_id`
Я получаю ошибку
1054 — Неизвестный столбец «A.created_at» в «предложении where»
Я думаю, что должно быть A.created_date
вместо A.created_at
select `plans`.`name`, `A`.`subscription_id`, `A`.`amount`,
`A`.`created_date`, `A`.`end_date`,
`A`.`subscription_status`, `users`.`email`, `A`.`plan_id`,
`A`.`user_id`, `usage`.`created_at` as `usagedate`, COUNT(usage.id) as
used_count from `subscriptions` A
left join `users` on `users`.`id` = `A`.`user_id`
left join `plans` on `A`.`plan_id` = `plans`.`Id`
left join `usage` on `A`.`user_id` = `usage`.`user_id`
where
`usage`.`created_at` between A.created_date and A.end_date
group by
`A`.`plan_id`
Я полагаю, что это должно быть a.created_date
SELECT `p`.`name`, `A`.`subscription_id`, `A`.`amount`, `A`.`created_date`, `A`.`end_date`, `A`.`subscription_status`, `u`.`email`, `A`.`plan_id`, `A`.`user_id`, `us`.`created_at` AS `usagedate`, COUNT(`us`.`id`) AS `used_count`
FROM `subscriptions` A
LEFT JOIN `users` u on `u`.`id` = `A`.`user_id`
LEFT JOIN `plans` p on `A`.`plan_id` = `p`.`Id`
LEFT JOIN `usage` us on `A`.`user_id` = `us`.`user_id`
WHERE `us`.`created_at` between `A`.`created_date` and `A`.`end_date`
GROUP BY `A`.`plan_id`