Fidelity Investments interview question

SQL queries DB Structure for given scenario Sorting program