American Express Interview Question

sql queries as some puzzles