Skip to content

Group By

Andrey Gershun edited this page May 28, 2015 · 7 revisions

GROUP BY

Syntax:

    SELECT ... GROUP BY expression, expression...
    SELECT ... GROUP BY CUBE(expression,...) | ROLLUP(expression,...) | GROUPING SETS(expression,...)  

Grouping by columns:

    var res = alasql('SELECT * FROM City GROUP BY Contient, Country');

Grouping by expressions:

    var res = alasql('SELECT b FROM Nums GROUP BY a%2');

The example:

    alasql('SELECT projects, FIRST(duration) AS duration, \
        FIRST([path]) AS [path], FIRST(application) AS application  \
        FROM json("timing_output") \
        GROUP BY projects, duration, [path], application \
        ORDER BY duration DESC',[],function(res){
          console.log(res);
    });

Try this example in jsFiddle

Grouping functions

    alasql('SELECT * FROM City GROUP BY ROLLUP(Continent, Country)');

See jsFiddle example for ROLLUP(), CUBE(), and GROUPING SETS().

See also: SELECT, HAVING, CUBE, ROLLUP, [GROUPING SETS](Grouping Sets)

Clone this wiki locally