try using "DISTINCT" instead of "GROUP BY", then use the "PARTITION BY" clause inside the first_value.