mysql中排序後根據排序的內容顯示序號,須要在子查詢中select @rownum:=0,只有外層的@rownum並不會起做用。java
select a.num, a.content, t.tagname, @rownum:=@rownum+1 as sortorder from (select count(*) as num, content, @rownum:=0 from action where actiontype='tag' group by content)a left join tag t on a.content=t.tagid order by a.num desc limit 10;
在沒有子查詢的狀況下,能夠在外面包一層查詢。mysql
SELECT n.*, @rownum:=@rownum+1 as sortorder from (SELECT COUNT(*) as num, vendor FROM device WHERE LENGTH(vendor)>0 GROUP BY vendor ORDER BY num DESC LIMIT 10) n, (SELECT @rownum := 0) r;