select c.personalAccount, ct.number, ct.from, ct.before, ct.isFactCalculation, ct.isFactRecalculation from rtneo$Contragent c join rtneo$Contract ct on ct.contragent.id = c.id where (not ct.isFactCalculation is null and ct.isFactCalculation = true) or (not ct.isFactRecalculation is null and ct.isFactRecalculation = true) order by c.personalAccount, ct.number asc