Пытаюсь выбрать сгруппированные данные из одной таблицы и дополнить количеством записей из другой.
Структура таблиц такая:
t1:
id
created_at (timestamp)
price (double)
t2:
id
created_at (timestamp)
type (enum(1,2))
Я пытаюсь сделать вот такой запрос:
select
date(t1.created_at) as date,
t1.price,
(select count(*) from t2 t21 where date(t1.created_at) = date(t21.created_at) and type = 1) as cnt1,
(select count(*) from t2 t22 where date(t1.created_at) = date(t22.created_at) and type = 2) as cnt2
from t1
group by date, t1.price
Получаю ошибку subquery uses ungrouped column "t1.created_at" from outer query
Как же мне выбрать count из другой таблице по дате?