我正在运行以下查询,以根据喜欢的总数获得所有类别中的业务排名。
SET @rownum = 0;
SELECT b.*
, (
SELECT f4.rank from business as b2 INNER JOIN (
select count(*) count, @rownum:=@rownum + 1 as rank, f3.* from favourites as f3 GROUP BY f3.business_id ORDER BY count DESC ) as f4 ON b2.id = f4.business_id WHERE b2.id = 8 && f4.category_id=c.id
)
as rank FROM business as b, category c where b.id=8
rank 在第一行之后给出 NULL,我应该怎么做才能将下一行的 @rownum 重置为 0?