标签:mysql
SELECT p_type,p_name,p_view,row_num from (
SELECT p_type,p_name,p_view,IF(@bak=p_type,@rownum:=@rownum+1,@rownum:=1) as row_num, @bak:=p_type
FROM
( SELECT p_type,p_name,p_view from products
order by p_type,p_view desc ) a , ( SELECT @rownum:=0,@bak:=‘‘) b
) c WHERE c.row_num <=2
IF函数
IF(条件,表达式1,表达式2)
如果条件成立 则返回表达式1,否则是2
标签:mysql
原文地址:http://chinaleo.blog.51cto.com/9897868/1934821