SQL grouping fix attempt #1