public function toSQL(Parameters $params, bool $inner_clause)
    {
        $groups = $this->getGroups();
        $having = $this->getHaving();

        if (count($groups) === 0)
            throw new QueryException("No groups in GROUP BY clause");
            
        $drv = $params->getDriver();

        $parts = array();
        foreach ($groups as $group)
        {
            $parts[] = $drv->toSQL($params, $group);
        }
        
        $having = !empty($having) ? ' ' . $drv->toSQL($params, $having) : "";

        return "GROUP BY " . implode(", ", $parts) . $having;
    }