最大月 是2021-10对应的数量1吗?
select t0.* from (
select 'A001' as bl_code,'2020-01' as date_code,46 as number_s union all
select 'A001' as bl_code,'2020-02' as date_code,27 as number_s union all
select 'A003' as bl_code,'2020-03' as date_code,66 as number_s union all
select 'A003' as bl_code,'2020-04' as date_code,28 as number_s union all
select 'A003' as bl_code,'2020-05' as date_code,54 as number_s union all
select 'A003' as bl_code,'2020-06' as date_code,35 as number_s
) t0
join (
select t.bl_code,max(date_code) as date_code from (
select 'A001' as bl_code,'2020-01' as date_code,46 as number_s union all
select 'A001' as bl_code,'2020-02' as date_code,27 as number_s union all
select 'A003' as bl_code,'2020-03' as date_code,66 as number_s union all
select 'A003' as bl_code,'2020-04' as date_code,28 as number_s union all
select 'A003' as bl_code,'2020-05' as date_code,54 as number_s union all
select 'A003' as bl_code,'2020-06' as date_code,35 as number_s
) t
group by t.bl_code
) t1 on t0.bl_code=t1.bl_code and t0.date_code=t1.date_code
原始明细
最后出来的结果