CitronAutobot
CitronAutobot

Reputation: 315

How to custom sort via mysql?

My table looks like this:

name    | 2013 | 2014
Adam    |    8 |    3
James   |    2 |    1
Total   |   18 |    9
Vince   |    8 |    5

This table is imported from Excel via csv

How do I get the result to look like this:

name    | 2013 | 2014
Adam    |    8 |    3
James   |    2 |    1
Vince   |    8 |    5
Total   |   18 |    9

I want to sort the results by "name", and put "Total" in the bottom of the result.

Upvotes: 0

Views: 24

Answers (1)

Ullas
Ullas

Reputation: 11556

You can use a CASE expression in ORDER BY.

Query

select * from your_table_name
order by case when name = 'Total' then 1 else 0 end,
name;

Upvotes: 2

Related Questions