I am trying to select grouped data from one table and add the number of records from another.
The structure of the tables is as follows:
t1: id created_at (timestamp) price (double) t2: id created_at (timestamp) type (enum(1,2)) I'm trying to make this request:
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 I get the error subquery uses ungrouped column "t1.created_at" from outer query
How can I select count from another table by date?