group by 多行变成一行-- (sum (case end case 也可以完成同样功能))

select *
  from (select mtab.*, rownum row_no
          from (select distinct decode(mss.equip_id,
                                       null,
                                       cosmos_config_pkg.GET_SiteName(mss.site_id),
                                       cosmos_config_pkg.GET_Equip_SerialName(mss.mdl_ver_id,
                                                                              mss.equip_id)) name,
                                null servPkgID,
                                null srevPkgName,
                                wi.work_item_id itemId,
                                wi.work_item_name itemName,
                                csp.serv_provider_name servProv,
                                decode(mss.trigger_typ_id,
                                       5,
                                       to_char(mss.start_dt, 'mm/dd/yyyy'),
                                       6,
                                       to_char(mss.start_dt, 'mm/dd/yyyy'),
                                       to_char(mss.start_value)) stDt,
                                decode(mss.trigger_typ_id,
                                       5,
                                       nvl(to_char(mss.end_dt, 'mm/dd/yyyy'),
                                           'EOT'),
                                       6,
                                       nvl(to_char(mss.end_dt, 'mm/dd/yyyy'),
                                           'EOT'),
                                       nvl(to_char(mss.end_value), 'EOT')) edDt,
                                decode(mss.trigger_typ_id,
                                       5,
                                       (select ef.freq_desc
                                          from cost_event_frequency ef
                                         where ef.freq_id = mss.freq_id),
                                       6,
                                       (select et.event_typ_name
                                          from cost_event_typ et
                                         where et.event_typ_id =
                                               mss.event_typ_id),
                                       1,
                                       'FFS',
                                       2,
                                       'AH',
                                       3,
                                       'AS',
                                       4,
                                       'FFH',
                                       '') periodicity,
                                decode(mss.trigger_typ_id,
                                       5,
                                       'NA',
                                       6,
                                       nvl(to_char(mss.event_occurence), 'ALL'),
                                       1,
                                       to_char(mss.freq_value),
                                       2,
                                       to_char(mss.freq_value),
                                       3,
                                       to_char(mss.freq_value),
                                       4,
                                       to_char(mss.freq_value),
                                       '') sequence,
                                nvl(cosmos_config_pkg.GET_Equip_SerialName(mss.mdl_ver_id,
                                                                           mss.ref_equip_id),
                                    'NA') refESN,
                                (select stt.trigger_typ_name
                                   from COST_SERV_TRIGGER_TYP stt
                                  where stt.trigger_typ_id =
                                        mss.trigger_typ_id) frequency,
                                null servType,
                                decode(mv.mdl_ver_typ_id, 1129, 'Y', 'N') crRenegInd,
                                decode(mv.mdl_ver_typ_id, 1127, 'Y', 'N') crStartInd,
                                decode(mv.mdl_ver_typ_id, 1130, 'Y', 'N') crModelInd,
                                decode(mv.mdl_ver_typ_id, 1150, 'Y', 'N') crActualInd,
                                decode(mv.mdl_ver_typ_id, 1087, 'Y', 'N') crOpDataInd,
                                decode(mv.mdl_ver_typ_id, 1151, 'Y', 'N') crFutureInd,
                                decode(mv.mdl_ver_typ_id, 1060, 'Y', 'N') crWorkInd,
                                decode(mv.mdl_ver_typ_id, 1090, 'Y', 'N') reTain1Ind,
                                decode(mv.mdl_ver_typ_id, 1091, 'Y', 'N') reTain2Ind,
                                decode(mv.mdl_ver_typ_id, 1094, 'Y', 'N') reTain3Ind,
                                decode(mv.mdl_ver_typ_id, 1095, 'Y', 'N') reTain4Ind
                  from cost_model_ver              mv,
                       cost_event_service          es,
                       cost_mdl_standalone_service mss,
                       cost_work_item              wi,
                       cost_work_item_ctlg         wic,
                       cost_work_item_category     cwic,
                       cost_service_provider       csp
                 where mv.mdl_id = 12991468
                   and es.mdl_ver_id = mv.mdl_ver_id
                   and mss.mdl_ver_id = mv.mdl_ver_id
                   and mss.mdl_standalone_serv_id = es.mdl_standalone_serv_id
                   and wi.work_item_id = mss.work_item_id
                   and wic.work_item_id = wi.work_item_id
                   and wic.ctlg_ver_id =
                       cosmos_config_pkg.GET_CATALOG_VERSION(mv.mdl_ver_id)
                   and cwic.work_item_category_id = wi.work_item_category_id
                   and csp.serv_provider_id = mss.serv_provider_id
                   and es.actualize_ind = 'P'
                   and mv.mdl_ver_typ_id in
                       (1060, 1087, 1127, 1129, 1130, 1150, 1151)
                   and mss.equip_id is null) mtab)
where row_no < = 100and row_no > 0





select distinct decode(mss.equip_id,
                       null,
                       cosmos_config_pkg.GET_SiteName(mss.site_id),
                       cosmos_config_pkg.GET_Equip_SerialName(mss.mdl_ver_id,
                                                              mss.equip_id)) name,
                null servPkgID,
                null srevPkgName,
                wi.work_item_id itemId,
                wi.work_item_name itemName,
                csp.serv_provider_name servProv,
                decode(mss.trigger_typ_id,
                       5,
                       to_char(mss.start_dt, 'mm/dd/yyyy'),
                       6,
                       to_char(mss.start_dt, 'mm/dd/yyyy'),
                       to_char(mss.start_value)) stDt,
                decode(mss.trigger_typ_id,
                       5,
                       nvl(to_char(mss.end_dt, 'mm/dd/yyyy'), 'EOT'),
                       6,
                       nvl(to_char(mss.end_dt, 'mm/dd/yyyy'), 'EOT'),
                       nvl(to_char(mss.end_value), 'EOT')) edDt,
                decode(mss.trigger_typ_id,
                       5,
                       (select ef.freq_desc
                          from cost_event_frequency ef
                         where ef.freq_id = mss.freq_id),
                       6,
                       (select et.event_typ_name
                          from cost_event_typ et
                         where et.event_typ_id = mss.event_typ_id),
                       1,
                       'FFS',
                       2,
                       'AH',
                       3,
                       'AS',
                       4,
                       'FFH',
                       '') periodicity,
                decode(mss.trigger_typ_id,
                       5,
                       'NA',
                       6,
                       nvl(to_char(mss.event_occurence), 'ALL'),
                       1,
                       to_char(mss.freq_value),
                       2,
                       to_char(mss.freq_value),
                       3,
                       to_char(mss.freq_value),
                       4,
                       to_char(mss.freq_value),
                       '') sequence,
                nvl(cosmos_config_pkg.GET_Equip_SerialName(mss.mdl_ver_id,
                                                           mss.ref_equip_id),
                    'NA') refESN,
                (select stt.trigger_typ_name
                   from COST_SERV_TRIGGER_TYP stt
                  where stt.trigger_typ_id = mss.trigger_typ_id) frequency,
                null servType,
                max(decode(mv.mdl_ver_typ_id, 1129, 'Y', 'N')) crRenegInd,
                max(decode(mv.mdl_ver_typ_id, 1127, 'Y', 'N')) crStartInd,
                max(decode(mv.mdl_ver_typ_id, 1130, 'Y', 'N')) crModelInd,
                max(decode(mv.mdl_ver_typ_id, 1150, 'Y', 'N')) crActualInd,
                max(decode(mv.mdl_ver_typ_id, 1087, 'Y', 'N')) crOpDataInd,
                max(decode(mv.mdl_ver_typ_id, 1151, 'Y', 'N')) crFutureInd,
                max(decode(mv.mdl_ver_typ_id, 1060, 'Y', 'N')) crWorkInd,
                max(decode(mv.mdl_ver_typ_id, 1090, 'Y', 'N')) reTain1Ind,
                max(decode(mv.mdl_ver_typ_id, 1091, 'Y', 'N')) reTain2Ind,
                max(decode(mv.mdl_ver_typ_id, 1094, 'Y', 'N')) reTain3Ind,
                max(decode(mv.mdl_ver_typ_id, 1095, 'Y', 'N')) reTain4Ind

--,mdl_ver_typ_id
  from cost_model_ver              mv,
       cost_event_service          es,
       cost_mdl_standalone_service mss,
       cost_work_item              wi,
       cost_work_item_ctlg         wic,
       cost_work_item_category     cwic,
       cost_service_provider       csp
where mv.mdl_id = 12991468
   and es.mdl_ver_id = mv.mdl_ver_id
   and mss.mdl_ver_id = mv.mdl_ver_id
   and mss.mdl_standalone_serv_id = es.mdl_standalone_serv_id
   and wi.work_item_id = mss.work_item_id
   and wic.work_item_id = wi.work_item_id
   and wic.ctlg_ver_id =
       cosmos_config_pkg.GET_CATALOG_VERSION(mv.mdl_ver_id)
   and cwic.work_item_category_id = wi.work_item_category_id
   and csp.serv_provider_id = mss.serv_provider_id
   and es.actualize_ind = 'P'
   and mv.mdl_ver_typ_id in (1060, 1087, 1127, 1129, 1130, 1150, 1151)
   and mss.equip_id is null
group by decode(mss.equip_id,
                 null,
                 cosmos_config_pkg.GET_SiteName(mss.site_id),
                 cosmos_config_pkg.GET_Equip_SerialName(mss.mdl_ver_id,
                                                        mss.equip_id)),
          null,
          null,
          wi.work_item_id,
          wi.work_item_name,
          csp.serv_provider_name,
          decode(mss.trigger_typ_id,
                 5,
                 to_char(mss.start_dt, 'mm/dd/yyyy'),
                 6,
                 to_char(mss.start_dt, 'mm/dd/yyyy'),
                 to_char(mss.start_value)),
          decode(mss.trigger_typ_id,
                 5,
                 nvl(to_char(mss.end_dt, 'mm/dd/yyyy'), 'EOT'),
                 6,
                 nvl(to_char(mss.end_dt, 'mm/dd/yyyy'), 'EOT'),
                 nvl(to_char(mss.end_value), 'EOT')),
          mss.trigger_typ_id,
         
          decode(mss.trigger_typ_id,
                 5,
                 'NA',
                 6,
                 nvl(to_char(mss.event_occurence), 'ALL'),
                 1,
                 to_char(mss.freq_value),
                 2,
                 to_char(mss.freq_value),
                 3,
                 to_char(mss.freq_value),
                 4,
                 to_char(mss.freq_value),
                 ''),
          nvl(cosmos_config_pkg.GET_Equip_SerialName(mss.mdl_ver_id,
                                                     mss.ref_equip_id),
              'NA'),
         
          mss.trigger_typ_id,
          null,
          mss.freq_id,
          mss.event_typ_id

猜你喜欢

转载自wang4674890.iteye.com/blog/1485706
今日推荐