您现在的位置是:首页 > 文章详情  网站首页文章详情

mysql查询会员的下一级和下二级总数

  • Administrator
  • 1202
  • 2020-04-24 10:11:19
  • 数据库
简介这里以ecshop和mysql的混合代码为例 $sql = 'SELECT user1.user_id, user1.real_name, (SELECT COUNT(*) FROM '.$ecs->table('users').' as user2 WHERE user...

这里以ecshop和mysql的混合代码为例

$sql = 'SELECT user1.user_id, user1.real_name,
(SELECT COUNT(*) FROM '.$ecs->table('users').' as user2 WHERE user_rank=1 AND user2.parent_id=user1.user_id ) as coun2,
(SELECT COUNT(*) FROM '.$ecs->table('users').' as user3 WHERE user_rank=1 AND user3.parent_id in (SELECT user22.user_id FROM '.$ecs->table('users').' as user22 WHERE user22.parent_id=user1.user_id) ) as coun3
 FROM '.$ecs->table('users').' as user1 WHERE user_rank=1';
$list = $db->getAll($sql);

个人觉得第三层的查询有点长,但是目前还没有找到比较好的方法代替。欢迎有想法的同学,留言。

文章评论

Top