mybatis 报错

mysql语句如下:select id, name, shop, time, count(b.gid) as num from table1 a left join table2 b on a.id = b.gid where a.shopId = #{shopId} group by id order by time desc

 

order by time 报错:Column time must be either aggregated, 

请教这是哪里错了?

正确写法如下: 

select id, name, shop, time, count(b.gid) as num 
from table1 a left join table2 b 
     on a.id = b.gid where a.shopId = #{shopId} 
group by id, name, shop, time order by time desc

错误原因:没有掌握分组的基础概念