3

I have table like this one

id    name
1     John
2     Mike
3     Zed
4     Teacher
5     Aaron
...........

How to make mysql query to get rows in ASC order by name but put "Teacher" at the top or something that starts with "Teacher"?

4

3 に答える 3

11
select * from your_table
order by case when name = 'Teacher' then 1 else 2 end,
         name 

MySQLの場合、0forfalseおよび1for を返すため、次のように機能しますtrue

select * from your_table
order by name <> 'Teacher',
         name 
于 2013-10-08T08:22:15.533 に答える
0
select * from table order by case when name like "Teacher%" then 1 else 2 end,name 

Teacher で始まる名前がアルファベット順に一番上に表示され、次に残りの名前が表示されます。例

Teacher
Teacher Aaron
Teacher Zed
Aaron
Zed
于 2013-10-08T08:29:52.347 に答える