这里以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);
个人觉得第三层的查询有点长,但是目前还没有找到比较好的方法代替。欢迎有想法的同学,留言。
网友评论