mysql - Run a query so that all values in any category that contains "Important" come first -


i have table whole bunch of rows. simplicity, we'll each row belongs categories a, b, c, or d. rows have values of important, not important, or boring. want sort such if category contains value important, values in category come first, important rows first. like:

a - important

a - important

a - not important

c - important

c - boring

b - boring

b - boring

d - not important

d - boring

select my_table.* my_table join (   select   category, sum(importance='important') number_important       my_table   group category ) t using (category) order t.number_important desc, category, importance 

see on sqlfiddle.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -