Why do I get a syntax error on this query?
I changed the code to the following one, and I don't get the error anymore.

$query = \Drupal::database()
    -&gt;select('simpleads_impressions', 's')
    -&gt;fields('s', array('nid'));
$query-&gt;addExpression("FROM_UNIXTIME(timestamp, '%Y-%m-%d')", 'utime');
$query-&gt;addExpression("UNIX_TIMESTAMP(FROM_UNIXTIME(timestamp, '%Y%m%d'))", 'date');
$query-&gt;addExpression('COUNT(*)', 'all_count');
$query-&gt;addExpression('COUNT(DISTINCT ip_address)', 'unique_count');
$query-&gt;where("FROM_UNIXTIME(timestamp, '%Y-%m-%d') BETWEEN CURDATE() - INTERVAL 1 DAY AND CURDATE() - INTERVAL 1 SECOND");
$query-&gt;groupBy('date');
$query-&gt;groupBy('nid');
$query-&gt;groupBy('timestamp');
$result = $query-&gt;execute()-&gt;fetchObject();