0
Name    1-3    4-6   7-9
------------------------
Dan       0      3     4
Jane      1      6     0
Mike      3      3     3
Dan       2      2     0
Jane      3      4     2
Dan       1      3     0

Here's order that needed to be done.

Name    1-3    4-6   7-9
------------------------
Dan       0      3     4
Dan       1      3     0
Dan       2      2     0
Mike      3      3     3
Jane      3      4     2
Jane      2      2     0

In short, the order by start with the highest number in field 7-9 have then group by the name, then order by again in each group name (in this ex. is Dan & Jane) according field 4-6 and 1-3

2 Answers 2

1

Try this query:

SELECT Name, `1-3`, `4-6`, `7-9`
FROM yourTable
ORDER BY `7-9` DESC, Name, `4-6` DESC, `1-3` DESC
Sign up to request clarification or add additional context in comments.

1 Comment

i think the example is coincidence.. It should be order by 7-9 first
0

I think there is typo in your desired result, and try this:

select t1.*
from yourtable t1
join (
  select Name, max(`7-9`) orderby
  from yourtable
  group by Name
  order by max(`7-9`)
) t2 on t1.Name = t2.Name
order by orderby desc, `4-6` desc, `1-3`

Demo Here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.