文章詳情頁
mysql group by 不能排序問題
瀏覽:147日期:2022-06-13 13:56:54
問題描述
我現在有一個文章表 有兩個字段 id 和 catid我想給 每個catid 有8個分類 列出 最新發的一篇文章
select * from post gruop by catid order by id desc;
這樣我只能取出 8條 id 最小的 也就是 最老的一篇文章 order by id 并不起作用
如何才能按照id號desc開始排序
問題解答
回答1:你select * 本來就是不嚴謹的寫法,只是mysql兼容性比較強默認給你放最小的,如果sql帶有group by,那么select里頭只能包含group by中的列或者是聚合函數,你評論說的沒法order by 是因為需要對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;回答3:
gruop by catid 寫在后面
相關文章:
1. css - 關于偽類背景問題2. html - 移動端radio無法選中3. apache - 怎么給localhost后面默認加上8080端口4. html5 - 如何實現圖中的刻度漸變效果?5. python - django的模板預加載6. mysql - 數據庫建字段,默認值空和empty string有什么區別 1107. python 計算兩個時間相差的分鐘數,超過一天時計算不對8. 關于Navicat連接到mysql,我改了root的密碼后,Navicat連接報錯1862?9. mysql起不來了,為什么?10. windows-7 - Win7中Vmware Workstatoin與Xampp中Apache服務器端口沖突?
排行榜
