按书价格排名:
方式一:无并列
select id,name,price,
@rownum := @rownum + 1 as rownum
from
(select @rownum:=0)r,
fviewtest1
order by price desc;
方式二:支持并列
select b.id,b.name as '书名',b.price as '书价格',count(bo.name)+1 as '书价格排名' from book b
left join book bo
on b.price > bo.price
group by b.id,b.name,b.price
order by count(bo.name)+1;
方式三:支持并列
select id,name,price,
@rownum := @rownum + 1 as tmp,
@incrnum :=case
when @rowtotal = price then @incrnum
when @rowtotal := price then @rownum
end as rownum
from
(select id,name,price from fviewtest1 order by price desc) as a,
(select @rownum := 0,@rowtotal := NULL,@incrnum := 0) b