美文网首页
mysql查询会员的下一级和下二级总数

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

作者: houxin | 来源:发表于2020-03-27 10:12 被阅读0次

    这里以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);
    

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

    相关文章

      网友评论

          本文标题:mysql查询会员的下一级和下二级总数

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