天天看點

mysql分組排序加序号

mysql分組排序後取出幾條記錄,

每一組你要顯示幾條資料?

用groupbycc

看看是你想要的嗎?

selectreason,floor(總數*0.8)from表明groupbyccorderbycc;

你看我的截圖

mysql分組排序加序号

mysql分組 排序 取前2條

可以寫為selectid,channel_id,timefromtablewheregroupbychannel_idorderbytimedesclimit2

這個真查不出來

恩,抱歉,我沒驗證過這段sql。我重新确定一下你的需求,上面的例子中你是要

11112010-05-13

21112010-05-12

這兩條記錄還是

11112010-05-13

32222010-05-13

這兩條記錄

前一種的話可以寫成selectid,channel_id,timefromtableorderbychannel_id,timedesclimit2

如果是後面一種可以寫成selectid,channel_id,timefromtablegroupbychannel_idorderbytimedesclimit2這裡我原本多寫了一個where

如果你還需要對channel進行排序的話可以寫成selectid,channel_id,timefromtablegroupbychannel_idorderbychannel_id,timedesclimit2

希望我的回答能對你有所幫助

本回答由提問者推薦

微網誌分組不能排序?微網誌分組不能排序

微網誌分組預設的是按時間排序

分組怎麼排?分組怎麼排序

1、更新微網誌分組資訊隻需在微網誌首頁左側分組欄,點選需修改資訊的分組名稱後的“扳手”辨別,選擇“管理該分組”,進入分組關注人頁面後即可在右上角進行分組名修改,分組删除操作;同時還可對該分組成員進行移除、更換分組或者取消關注。2、調整微網誌分組排列順序,點選需移動分組名稱後的“扳手”辨別,選擇“分組排序”拖動需要移動的分組到指定位置即可。3、建立新分組,在微網誌首頁左側分組一欄可以找到“建立新分... 點此-> 檢視詳細内容。

Mysql 分組并排序

1、按rowno分組後,每個rowno隻有一條資料。是以排序不可能同時按rowno, count來排序。

2、感覺你應該隻按count排序

------------------
SELECT rowno
,COUNT(*) AS Num
FROM Table1
GROUP BY rowno
ORDER BY COUNT(*)用分組函數來做,假如你的表名是table_name
select a.*
from table_name a,(select product,max(date) max_date from table_name group by product) b
where a.product=b.product and a.date=b.max_date;select rowno,count(*) from table1 group by rowno order by rowno,count(*);      

資料庫排序并且取每個分組的前三條

select t2.* from
(select t1.*,row_number() over
(partition by id order by fee desc) rn from tabname t1) t2  
where rn<=3select * from 
selectrow_number() over(partition by '分組' order by '日期') as rownum-- 排序并分組
, *-- 所需顯示的字段
from 表
) as t
where t.rownum = 1