Mercer Interview Question

some tricky sql queries related to joins, and group functions,triggers