select c.personalAccount, c.name, CASE WHEN (select count(s) from sec$SessionLogEntry s where s.user.login = c.user.login) > 0 THEN 'Заходил' ELSE 'Не заходил' END from rtneo$Contragent c where not c.type = 3 and (lower(c.name) like lower('%%садовод%%') or lower(c.name) like lower('%%дачн%%')) and not lower(c.name) like lower('%%удачн%%')