1. 程式人生 > >oracle 給分組加序號

oracle 給分組加序號

做報表需要給各車間的資料顯示到一起,每行顯示三個車間的資料,按照分組的序號換行顯示

DENSE_RANK() OVER(ORDER BY b.dept_name) grp

--整段

select * from (
select m.jxcdl,
              DENSE_RANK() OVER(ORDER BY b.dept_name) grp,
               b.dept_name as shopname,
               c.dept_name as teamname,
               t.*
          from hm_machine_asset t
          left join (select a.model_id,
                           t.data_text   as device_class,
                           a.equip_model,
                           a.remark      as jxcdl
                      from hm_train_model a
                      left join mf_dict_data t
                        on a.device_class = t.data_value
                     where t.dict_id = 'hm.asset.type') m
            on t.device_class = m.model_id
          left join mf_department b
            on b.dept_id = t.assigned_shop
          left join mf_department c
            on c.dept_id = t.assigned_team
         where t.rescue_equip_state = '0'
           and t.assigned_team is not null
           and t.asset_type = '0' ) m
 order by shopname, teamname,jxcdl