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;