mysql group by 不能排序问题
PHPz
PHPz 2017-04-17 16:52:09
0
3
1118

我现在有一个文章表 有两个字段 id 和 catid
我想给 每个catid 有8个分类 列出 最新发的一篇文章

select * from post gruop by catid order by id desc;

这样我只能取出 8条 id 最小的 也就是 最老的一篇文章 order by id 并不起作用

如何才能按照id号desc开始排序

PHPz
PHPz

学习是最好的投资!

reply all(3)
阿神

Your select * is originally not a rigorous way of writing, but MySQL has strong compatibility and defaults to the smallest one. If SQL has group by, then the select can only contain columns in group by or aggregation functions , you commented that order by cannot be done because you need to add an alias to the column after max.

select max(id) id, catid from post group by catid order by id desc;

小葫芦
select * from post gruop by catid order by id desc;
Ty80

gruop by catid written at the back

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template