mysql order by greatest then second greatest -


i've got table of scores:

user / score 1 / score 2 / score 3 person 1: 10 21 7 person 2: 21 4 20 person 3: 1 5 22 

i'm trying sort them highest individual score , second highest individual score.

the first part can do.

i know how order greatest(score1, score2, score3) desc

but i'm not sure how set secondary ordering second greatest if it's tie it's decided players second highest score.

so ideally results be:

user / score 1 / score 2 / score 3 person 3: 1 5 22 person 2: 21 4 20 person 1: 10 21 7 

does have ideas?

try this.

   select name, score1, score2, score3 score     order greatest(score1, score2, score3) desc,         (score1+ score2+ score3) - greatest(score1, score2, score3) -                                               least(score1, score2, score3) desc,     least(score1, score2, score3) desc; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -