SELECT COUNT(gr_companies.id) AS count FROM gr_companies LEFT JOIN xposts ON xposts.id=gr_companies.cat_id LEFT JOIN users ON users.id=gr_companies.user_id WHERE gr_companies.comp_id_place= AND gr_companies.is_enabled=1 AND gr_companies.is_blocked=0 AND ((gr_companies.date2 IS NOT NULL and gr_companies.data_time_end>='2018-01-18 10:49:57' ) OR (gr_companies.date2 IS NULL and gr_companies.data_time_start>='2018-01-18 10:49:57' ))