1. A method comprising: receiving a query comprising an extended group-by clause, the extended group-by clause comprising an extended group-by operator and a first set of group-by columns; wherein the query comprises one or more distinct aggregate functions and one or more non-distinct aggregate functions; constructing an initial subquery that generates a partially aggregated initial temporary (PAIT) table when executed, wherein the initial subquery comprises a GROUP BY clause that includes a second set of group-by columns comprising the first set of group-by columns of the extended group-by clause of the query and one or more columns specified by the one or more distinct aggregate functions; constructing one or more subqueries that compute groupings indicated by the extended group-by operator based on the PAIT table generated by the initial subquery; wherein the method is performed by one or more computing devices.