ZS Associates interview question

Sorting using sql in an optimal way