sql语句求解。mysql 系统是三级分销系统,想要一个 按照 分销团队下线...
发布网友
发布时间:2024-09-17 04:25
我来回答
共1个回答
热心网友
时间:2024-10-01 02:42
select sum(count) from (
--一级
select count(*) as count from table_name where pid= 'id'
union all
--二级
select count(*) as count from table_name t1
inner join table_name t2
on t1.pid = t2.id
where t2.pid= 'id'
union all
--三级
select count(*) as count from table_name t1
inner join (
select id,pid from table_name t1
inner join table_name t2
on t1.pid = t2.id
where t2.pid= 'id'
) t2 on t1.pid = t2.id
)
热心网友
时间:2024-10-01 02:42
select sum(count) from (
--一级
select count(*) as count from table_name where pid= 'id'
union all
--二级
select count(*) as count from table_name t1
inner join table_name t2
on t1.pid = t2.id
where t2.pid= 'id'
union all
--三级
select count(*) as count from table_name t1
inner join (
select id,pid from table_name t1
inner join table_name t2
on t1.pid = t2.id
where t2.pid= 'id'
) t2 on t1.pid = t2.id
)