N26 Interview Question

Q1: Given some data write an optimal SQL query that outputs the following table... Q2. Given an SQL query write a python script that gives the same output.