select p_type,p_name,p_view,
IF(@pre=p_type,@rownum:=@rownum+1,@rownum:=1),@pre:=p_type from
(select a.p_type,a.p_name,a.p_view from products a GROUP BY a.p_type,a.p_name order by a.p_type desc, a.p_view desc ) a,
(select @pre:="",@rownum:=0 ) b
解析 如果上一个p_type 不同 就rownumber=1 否则就加1