Skip to content
Advertisement

Order table by the total count but do not lose the order by names

I have a table, consisting of 3 columns (Person, Year and Count), so for each person, there are several rows with different years and counts and the final row with total count. I want to keep the table ordered by Name, but also order it by the total count.

So the rows should be ordered by sum, but also grouped by the Person and ordered by year. When I am trying to order by sum, of course, both person and years are messed up. Is there a way to sort like this?

Advertisement

Answer

You’ve stored those “total” rows as well? Gosh! Why did you do that?


Anyway: if you

  • compute rank for rows whose year column is equal to 'total' and
  • add case expression into the order by clause,

you might get what you want:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement