直接修改红色部分代码即可;
加入ROWNUM 保证了左表查询的顺序不被改变。
select flighleft.*,
flightright.* from
(
SELECT T.* , ROWNUM ROW_NUM
FROM (
select bm.id,bm.classname from billbm bm
group by bm.budgetdept,bm.classname,bm.id
order by bm.budgetdept
) T
) flighleft
left join (
select * from billbm bm
)flightright on flighleft.id = flightright.id
order by flighleft.ROW_NUM