FNZ interview question

Coding challenge in Java and SQL