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}");
网友评论