# How to sort the data by several columns (some ascending and some descending)?

I have sorted the data firstly by the 3rd column and then by the 2nd column as below:-

a = RandomInteger[20, {30, 3}]
SortBy[a, {#[[3]], #[[2]]} &]


As you can see, now they are both sorted in ascending order. But I need the 3rd column to be sorted by descending order, while the 2nd should be sorted in ascending order. What should I do?

Many thanks!

SortBy[a, {-#[[3]], #[[2]]} &];

• Thanks... I was stuck at how to combine the Greater option with it... – H42 Jun 15 '18 at 22:58