Fix group by bug