/**
  * @param string $table
  * @return int
  */
 public function count($table = '')
 {
     $sql = sprintf('SELECT COUNT(*) FROM %s', $table !== '' ? $this->db->quoteIdentifier($table) : $this->from);
     if ($this->where !== '') {
         $sql .= ' WHERE ' . $this->where;
     }
     if ($this->groupBy !== '') {
         $sql .= ' GROUP BY ' . $this->groupBy;
     }
     if ($this->having !== '') {
         $sql .= ' HAVING ' . $this->having;
     }
     if ($this->orderBy !== '') {
         $sql .= ' ORDER BY ' . $this->orderBy;
     }
     $sql .= ';';
     $this->reset();
     return $sql;
 }