adding auto-generation for group by SQL