:
select B.id
from A right join B on A.ticket = B.id
where B.state not in (3, 4, 10) and B.disable = 0
group by B.id
having count(case when A.ticket is not null and A.type = 0 then 1 end) = 0;
, B, A, , A.type = 0.
:
select B.*
from A right join B on A.ticket = B.id
where B.state not in (3, 4, 10) and B.disable = 0 and coalesce(A.type, 1) <> 0
, , , , A.type = 0.
, coalesce - .