revised query group by on tabular