美文网首页
mysql 查询 - 个人记录

mysql 查询 - 个人记录

作者: NO我的错 | 来源:发表于2021-03-17 20:27 被阅读0次

    1.mysql 子查询使用父查询字段作为条件,查询B表数量

    $unit = "公司";
    $department = "部门";
    Db::query("select a.ep_id,a.ep_topRoleId,
             (select count(us_id) from tb_user as b where find_in_set(b.us_roleid, a.ep_topRoleId) and us_unit='{$unit}' and us_department='{$department}') as num 
             from tb_exam_paper as a");
    

    2.mysql 根据某字段排行,获取当前用户排名

    Db::query("SELECT * FROM
              (SELECT ui_uid,ui_integral,ui_time,(@rank:=@rank+1) AS us_rank FROM tb_user_integral_current, (SELECT (@rank:=0)) b 
              WHERE {$where} ORDER BY ui_integral DESC,ui_uid Asc) c WHERE ui_uid={$uid}");
    
    

    相关文章

      网友评论

          本文标题:mysql 查询 - 个人记录

          本文链接:https://www.haomeiwen.com/subject/klaecltx.html