Double Line interview question

Code : Python and SQL