SELECT {field_date_formatted} AS `period`, COUNT(*) AS {object} FROM `Profiles` INNER JOIN `bx_facebook_accounts` ON (`id_profile` = `ID`) WHERE {field_date} >= '{from}' AND {field_date} <= '{to}' GROUP BY `period` ORDER BY {field_date} ASC