解决方案 »

  1.   

    create view xxx as
    with
      a as (select * from cfg_callerrule_info where rule_type=1),
      b as (select * from cfg_callerrule_info where rule_type=2)
    select nvl(a.policy_id,b.policy_id) policy_id,a.time_slice,a.threshold,b.time_slice,b.threshold,
           (case when a.rule_type+b.rule_type=3 then 1 end)
    from a full join b on a.policy_id=b.policy_id;
      

  2.   

    CREATE VIEW v_cfg_callerrule_info(policy_id,hang_up_time_slice,hang_up_threshold,conn_time_slice,conn_threshold,relation) AS
    SELECT c1.policy_id,
           c1.time_slice,
           c1.threshold,
           c2.time_slice,
           c2.threshold,
           CASE
             WHEN (c1.relation IS NOT NULL) THEN
              c1.relation
             WHEN (c2.relation IS NOT NULL) THEN
              c2.relation
             ELSE
              NULL
           END
      from cfg_callerrule_info c1, cfg_callerrule_info c2
     where c1.policy_id = c2.policy_id
       and c1.rule_type < c2.rule_type
    union
    select c1.policy_id,
           c1.time_slice,
           c1.threshold,
           c2.time_slice,
           c2.threshold,
           c1.relatio
      from cfg_callerrule_info t1
     where t1.policy_id in (select t1.policy_id
                              from cfg_callerrule_info t1
                             where t1.rule_type in (1, 2)
                             group by t1.policy_id
                            having count(rule_type) < 2) t2