获取用户当前排名(我的是根据热度值获取用户周排名最高的食谱)

第一步:根据排名字段获取用户热度值最高的食谱排名
$sql = 'SELECT b.recipe_id,b.heat_num,b.user_id,b.rownum FROM(SELECT t.*, @rownum := @rownum + 1 AS rownum 
        FROM (SELECT @rownum := 0) r,(SELECT user_id,recipe_id,heat_num,add_time,recipe_type FROM ns_platform_recipe 
        WHERE add_time between ' .$start_time.' and '.$end_time. ' and recipe_type = 1 ORDER BY `heat_num` DESC) AS t) AS b 
        where b.user_id = ' .$uid;

第二步:

Db::query($sql);

根据自己的实际情况修改即可,因为是后期整理  找不到原先的地址了

你可能感兴趣的:(工作随笔,mysql)