sql带有group by,那么select里头只能包含group by by的列或者是聚合函数
select max(id) id, catid from post group by catid order by id desc;
写的顺序:select ... from... where.... group by... having... order by..
执行顺序:from... where...group by... having.... select ... order by...
编写过程:select distinct ... from ... join ... on ... where.... group by ... having ... order by ... limit ...
解析过程:from ... on ... join ... where.... group by... having ... select distinct ... order by... limit ...
本文详细介绍了 SQL 中 Group By 子句的使用方法,包括其语法结构、执行顺序及编写过程。并强调了当 SQL 语句中包含 Group By 时,Select 子句中只能出现被 Group By 列或聚合函数。

1251

被折叠的 条评论
为什么被折叠?



