22,210
社区成员
发帖
与我相关
我的任务
分享
with cte as
(
select * from azpxx where 序号=210
union all
select a.* from azpxx a join cte b on a.所属人1=b.序号 where b.性别='男'
)
select * from cte order by 辈分
相反一下就OK了
with cte as
(select * from azpxx where 序号=210
union all
select a.*
from azpxx a
inner join cte b on a.所属人=b.序号
where a.性别='男'
and not exists(select 1
from azpxx c
where c.所属人=b.序号 and c.性别='男' and c.排行<a.排行)
)
select * from cte order by 辈分
with cte as
(select * from azpxx where 序号=210
union all
select a.*
from azpxx a
inner join cte b on a.所属人=b.序号
where a.性别='男'
and not exists(select 1
from azpxx c
where c.所属人=b.序号 and c.性别='男' and c.排行>a.排行)
)
select * from cte order by 辈分