Mysql 取出数据并显示行号 (假设按p_view倒排序)

IFNULL(expr1,expr2) ide

   expr1 不为 NULL,则 IFNULL() 的返回值为 expr1; 不然其返回值为 expr2it


select  p_name,p_type,p_view, IFNULL(@rownum:=@rownum+1,@rownum:=1)  from products a    ORDER BY p_view desc class


问题又来了,第二次运行 @rownum不是从1开始的select



select  p_name,p_type,p_view,@rownum:=@rownum+1 di

     from products a,(select @rownum:=0) b    ORDER BY p_view desc view

相关文章
相关标签/搜索