select A.id,A.mc,count(distinct A1.id) cnt from A left join A1 on A.id<=A1.id and A.mc=A1.mc group by A.id
select A.id,A.mc,count(distinct A1.id) cnt from A left join A1 on A.id>=A1.id and A.mc=A1.mc group by A.id
查询结果
select A.id,A.mc,count(distinct A1.id) cnt from A left join A1 on A.id<=A1.id and A.mc=A1.mc group by A.id
select A.id,A.mc,count(distinct A1.id) cnt from A left join A1 on A.id>=A1.id and A.mc=A1.mc group by A.id
查询结果