0

嘿,我的问题是这样的,它可能对其他人也有用,我有一个带有 instance_id 的订单,该订单有几张带有不同 ticket_number 作为 sr_num 的票,但都有相同的服务实例 id。工单可能处于打开关闭或正在进行中的不同阶段,假设一个订单有 4 张工单,并且有很多订单有 4 个或更少的工单我找到一种工单的所有打开工单,获取它的 service_instance_id 并与之对应,查找对该订单开放的其他票。

使用以下查询,我可以找到它,但它们都在一个之下,我希望它用于特定订单,所有 4 票信息都在一行中,如果该订单的特定票已关闭,它不应该是显示

 select a.sr_num Acceptance_TT, a.act_open_dt Acceptance_Date, e.login Acceptance_Owner , c.sr_area, c.sr_num, c.act_open_dt, d.login, case when c.sr_stat_id in ('Closed','Cancelled') then '-' else c.sr_stat_id end TT_Status
    from 
    siebel.s_srv_req a -- GOC TT
    ,siebel.s_order_item b -- ServiceInstanceID
    ,siebel.s_srv_req c -- Project Management
    ,siebel.s_user d -- Owner
    ,siebel.s_user e -- GOC Owner
    where 
    a.sr_area = 'GOC Acceptance' and a.sr_num='20130601-3-28'
    and a.sr_stat_id in ('Open - GOC')
    and a.x_service_instance_id = b.row_id
    and c.x_service_instance_id = b.row_id
    and c.sr_area = 'Project Management'
    --and c.sr_stat_id not in ('Closed','Cancelled')
    and c.owner_emp_id = d.row_id
    and a.owner_emp_id = e.row_id  PM 5:39 
    UNION all
    select a.sr_num Acceptance_TT, a.act_open_dt Acceptance_Date, e.login Acceptance_Owner, c.sr_area, c.sr_num, c.act_open_dt, d.login, case when c.sr_stat_id in ('Closed','Cancelled') then '-' else c.sr_stat_id end TT_Status
    from 
    siebel.s_srv_req a -- GOC TT
    ,siebel.s_order_item b -- ServiceInstanceID
    ,siebel.s_srv_req c -- Provisioning
    ,siebel.s_user d -- Owner
    ,siebel.s_user e -- GOC Owner
    where 
    a.sr_area = 'GOC Acceptance' and a.sr_num='20130601-3-28'
    and a.sr_stat_id in ('Open - GOC')
    and a.x_service_instance_id = b.row_id
    and c.x_service_instance_id = b.row_id
    and c.sr_area = 'Provisioning'
    --and c.sr_stat_id not in ('Closed','Cancelled')
    and c.owner_emp_id = d.row_id
    and a.owner_emp_id = e.row_id  PM 5:39 
    UNION all
    select a.sr_num Acceptance_TT, a.act_open_dt Acceptance_Date, e.login Acceptance_Owner, c.sr_area, c.sr_num, c.act_open_dt, d.login, case when c.sr_stat_id in ('Closed','Cancelled') then '-' else c.sr_stat_id end TT_Status
    from 
    siebel.s_srv_req a -- GOC TT
    ,siebel.s_order_item b -- ServiceInstanceID
    ,siebel.s_srv_req c -- CE Implementation
    ,siebel.s_user d -- Owner
    ,siebel.s_user e -- GOC Owner
    where 
    a.sr_area = 'GOC Acceptance' and a.sr_num='20130601-3-28'
    and a.sr_stat_id in ('Open - GOC')
    and a.x_service_instance_id = b.row_id
    and c.x_service_instance_id = b.row_id
    and c.sr_area = 'CE Implementation'
    --and c.sr_stat_id not in ('Closed','Cancelled')
    and c.owner_emp_id = d.row_id
    and a.owner_emp_id = e.row_id  
4

1 回答 1

1

试试这个并分享结果,我没有你的配置要测试

with tab as (
    select a.sr_num Acceptance_TT, 
           a.act_open_dt Acceptance_Date, 
           e.login Acceptance_Owner, 
           c.sr_area, 
           c.sr_num, 
           c.act_open_dt, 
           d.login, 
           case when c.sr_stat_id in ('Closed','Cancelled') then '-' else c.sr_stat_id end TT_Status
    from 
    siebel.s_srv_req a -- GOC TT
    ,siebel.s_order_item b -- ServiceInstanceID
    ,siebel.s_srv_req c -- CE Implementation
    ,siebel.s_user d -- Owner
    ,siebel.s_user e -- GOC Owner
    where 
    a.sr_area = 'GOC Acceptance' and a.sr_num='20130601-3-28'
    and a.sr_stat_id in ('Open - GOC')
    and a.x_service_instance_id = b.row_id
    and c.x_service_instance_id = b.row_id
    and c.sr_area in ('CE Implementation', 'Project Management', 'Provisioning')
    and c.owner_emp_id = d.row_id
    and a.owner_emp_id = e.row_id
    )
 select * 
   from tab 
  pivot (min(TT_Status) as TT_Status for (sr_area) in ('CE Implementation' as CE, 'Project Management' as PM, 'Provisioning' as PRO))
于 2014-01-27T04:32:14.370 回答