-- 分组加编号 sql:
select
b.eps400,
b.max_report_id,
row_number() over (partition by b.eps400 order by b.max_report_id desc) nums
from (
select eps400, transfer_num, max(report_id) max_report_id
from t_report_num_seat_bind_approve a
where a.approve_date is not null
group by eps400, transfer_num
) b
-- rs:
4000000003,397686,1
4000000003,396690,2
4000000005,285728,1
4000000005,285655,2
4000000005,9446,3
4000000040,231967,1
4000000055,64999,1
-- 分组编号,如果编号大于10,取一半,sql:
select bb.eps400, case when max(bb.nums) >= 10 then round(max(bb.nums) * 0.5) else max(bb.nums) end max_nums
from (
select b.eps400,
b.max_report_id,
row_number() over (partition by b.eps400 order by b.max_report_id desc) nums
from (
select eps400, transfer_num, max(report_id) max_report_id
from t_report_num_seat_bind_approve a
where a.approve_date is not null
group by eps400, transfer_num
) b
) bb
group by bb.eps400;
-- rs:
4000000003,2
4000000005,3
4000000040,1
4000000055,1