【问题标题】:Maximo classification summary queryMaximo 分类汇总查询
【发布时间】:2021-12-17 02:47:02
【问题描述】:

Maximo 资产管理 7.6.1.2;甲骨文 19c:

我想在 db 视图中总结 CLASSSTRUCTURE 和 CLASSUSEWTIH 表如下:

  • CLASSSTRUCTUREID
  • 级别编号
  • LEVEL_COUNT
  • 分类 ID
  • HIERARCHYPATH(CLASSSTRUCTURE 中现有的自定义持久字段)
  • 家长
  • TOP_CLASSSTRUCTUREID
  • TOP_CLASSIFICATIONID
  • 使用

如何使用 Oracle SQL 做到这一点?

【问题讨论】:

    标签: maximo


    【解决方案1】:

    我可以使用Oracle分层查询(CONNECT BY):

    --create or replace view cgclassstructure_vw as (
    select
        cl.classstructureid,
        level as pseudo_level, --the CLASSANCESTOR table already has an OOB HIERARCHYLEVEL column. But the level numbers in that column are in reverse-order (sorted descending) and the level numbers start at 0 instead of 1 -- which isn't what we want.
        count(level) over (partition by connect_by_root(cl.classificationid)) as level_count,
        cl.classificationid,
        cl.description,
        cl.cghierarchypath,
        --ltrim(sys_connect_by_path(cl.classificationid, ' \ '),' \ ') as hierarchypath,
        cl.parent,
        cl.haschildren,
        connect_by_root(cl.classstructureid) as top_classstructureid,
        connect_by_root(cl.classificationid) as top_classificationid,
        uw.usewith,
        cl.cgactive
    from 
        maximo.classstructure cl
    left join
        (
        select 
            classstructureid,
            listagg(objectname,', ') within group(order by objectname) as usewith
        from 
            maximo.classusewith
        group by 
            classstructureid
        ) uw
        on cl.classstructureid = uw.classstructureid
    start with cl.parent is null
    connect by prior cl.classstructureid = parent
    order by
        top_classstructureid,  --handles scenarios like the FACILITIES classifications -- we have top-level FACILITIES classifications for both ASSET and WO (different sets of classifications)
        cghierarchypath
    --)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-05
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 2011-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多