Intact Insurance interview question

data frame manipulations and sql query