Automating Sql Query Interview Question