Peewee: fn.GROUP_CONCAT should support ORDER BY

Created on 20 Jan 2017  路  1Comment  路  Source: coleifer/peewee

From MySQL Docs, GROUP_CONCAT supports ORDER BY

mysql> SELECT student_name,
    ->     GROUP_CONCAT(DISTINCT test_score
    ->               ORDER BY test_score DESC SEPARATOR ' ')
    ->     FROM student
    ->     GROUP BY student_name;

Most helpful comment

Try this:

fn.GROUP_CONCAT(Clause(
    SQL('Distinct'),
    MyModel.test_score,
    SQL('ORDER BY'),
    MyModel.test_score,
    SQL('DESC SEPARATOR \' \'')))

Not very clean but that should hopefully help you get the SQL you need.

>All comments

Try this:

fn.GROUP_CONCAT(Clause(
    SQL('Distinct'),
    MyModel.test_score,
    SQL('ORDER BY'),
    MyModel.test_score,
    SQL('DESC SEPARATOR \' \'')))

Not very clean but that should hopefully help you get the SQL you need.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kadnan picture kadnan  路  3Comments

kalimalrazif picture kalimalrazif  路  3Comments

rayzorben picture rayzorben  路  4Comments

alexlatchford picture alexlatchford  路  4Comments

lucasrc picture lucasrc  路  5Comments