how to write SQl query for the given problem below with a self join

Printable View