ZS Associates Interview Question

Sorting using sql in an optimal way