sql - MySQL group_concat() ordering by case statement values -
in mysql group_concat()
clause, i'm trying order resulting values of case statement. following query configuration orders things.name
not order 'non-us' or 'unknown' values within same context.
select things.id ,group_concat(distinct case when things.name <> 'united states' 'non-us' when things.name null 'unknown' else things.name end order name separator ', ') things group things.id
i want this, it's not working:
select things.id ,group_concat(distinct (case when things.name <> 'united states' 'non-us' when things.name null 'unknown' else things.name end) new_name order new_name separator ', ') things group things.id
is there way sort "new_name" without using sub-queries/ nested queries?
you can accomplish ordering column position instead of column name.
for case order 1
should work.
select things.id ,group_concat(distinct case when things.name <> 'united states' 'non-us' when things.name null 'unknown' else things.name end order 1 separator ', ') things group things.id
Comments
Post a Comment