select * from a1 join b1 on b1.a1_id = a1.id group by a1.date having max(case when type = '1z' then 1 else 0 end) = 1 and max(case when type = '2z' then 1 else 0 end) = 1;
select * from a1 join b1 on b1.a1_id = a1.id group by a1.date having max(case when type = '1z' then 1 else 0 end) = 1 and max(case when type = '2z' then 1 else 0 end) = 1;
вот почему * если ты хоешь получить только одно поле.