DBA Data[Home] [Help]

MATERIALIZED VIEW: APPS.BIL_BI_OP22_G_MV

Source


SELECT
    'NEW' umarker
    ,op21.opty_creation_time_id effective_time_id
    ,op21.parent_sales_group_id parent_sales_group_id
    ,op21.sales_group_id sales_group_id
    ,op21.salesrep_id salesrep_id
    ,SUM(new_opty_amt) new_opty_amt
    ,SUM(new_opty_amt_s) new_opty_amt_s
    ,NULL won_opty_amt
    ,NULL won_opty_amt_s
    ,NULL lost_opty_amt
    ,NULL lost_opty_amt_s
    ,NULL no_opty_amt
    ,NULL no_opty_amt_s
    ,NULL cnv_opty_amt
    ,NULL cnv_opty_amt_s
    ,SUM(nfp_yr) nfp_yr
    ,SUM(nfp_yr_s) nfp_yr_s
    ,SUM(nfp_qtr) nfp_qtr
    ,SUM(nfp_qtr_s) nfp_qtr_s
    ,SUM(nfp_per) nfp_per
    ,SUM(nfp_per_s) nfp_per_s
    ,SUM(nfp_wk) nfp_wk
    ,SUM(nfp_wk_s) nfp_wk_s
    ,SUM(CASE WHEN new_opty_cnt IS NULL THEN NULL ELSE 1 END) new_opty_cnt
    ,NULL won_opty_cnt
    ,NULL lost_opty_cnt
    ,NULL no_opty_cnt
    ,NULL cnv_opty_cnt
    ,NULL latest_open_opty_cnt
    ,COUNT(nfp_yr) nfp_yr_xcnt
    ,COUNT(nfp_yr_s) nfp_yr_xcnt_s
    ,COUNT(nfp_qtr) nfp_qtr_xcnt
    ,COUNT(nfp_qtr_s) nfp_qtr_xcnt_s
    ,COUNT(nfp_per) nfp_per_xcnt
    ,COUNT(nfp_per_s) nfp_per_xcnt_s
    ,COUNT(nfp_wk) nfp_wk_xcnt
    ,COUNT(nfp_wk_s) nfp_wk_xcnt_s
    ,COUNT(new_opty_amt) new_opty_xcnt
    ,COUNT(new_opty_amt_s) new_opty_xcnt_s
    ,NULL won_opty_xcnt
    ,NULL won_opty_xcnt_s
    ,NULL lost_opty_xcnt
    ,NULL lost_opty_xcnt_s
    ,NULL no_opty_xcnt
    ,NULL no_opty_xcnt_s
    ,NULL cnv_opty_xcnt
    ,NULL cnv_opty_xcnt_s
    ,COUNT(CASE WHEN new_opty_cnt IS NULL THEN NULL ELSE 1 END) new_opty_cnt_xcnt
    ,NULL won_opty_cnt_xcnt
    ,NULL lost_opty_cnt_xcnt
    ,NULL no_opty_cnt_xcnt
    ,NULL cnv_opty_cnt_xcnt
    ,NULL latest_open_opty_cnt_xcnt
    ,COUNT(*) all_xcnt
  FROM
    bil_bi_op21_g_mv op21
  GROUP BY
    op21.opty_creation_time_id
    ,op21.parent_sales_group_id
    ,op21.sales_group_id
    ,op21.salesrep_id
  UNION ALL
  SELECT
    'WLN' umarker
    ,op21.opty_effective_time_id effective_time_id
    ,op21.parent_sales_group_id
    ,op21.sales_group_id
    ,op21.salesrep_id
    ,NULL new_opty_amt
    ,NULL new_opty_amt_s
    ,NULL won_opty_amt
    ,NULL won_opty_amt_s
    ,SUM(lost_opty_amt) lost_opty_amt
    ,SUM(lost_opty_amt_s) lost_opty_amt_s
    ,SUM(no_opty_amt) no_opty_amt
    ,SUM(no_opty_amt_s) no_opty_amt_s
    ,NULL cnv_opty_amt
    ,NULL cnv_opty_amt_s
    ,NULL nfp_yr
    ,NULL nfp_yr_s
    ,NULL nfp_qtr
    ,NULL nfp_qtr_s
    ,NULL nfp_per
    ,NULL nfp_per_s
    ,NULL nfp_wk
    ,NULL nfp_wk_s
    ,NULL new_opty_cnt
    ,SUM(CASE WHEN won_opty_cnt IS NULL THEN NULL ELSE 1 END) won_opty_cnt
    ,SUM(CASE WHEN lost_opty_cnt IS NULL THEN NULL ELSE 1 END) lost_opty_cnt
    ,SUM(CASE WHEN no_opty_cnt IS NULL THEN NULL ELSE 1 END) no_opty_cnt
    ,NULL cnv_opty_cnt
    ,SUM(CASE WHEN latest_open_opty_cnt IS NULL THEN NULL ELSE 1 END) latest_open_opty_cnt
    ,NULL nfp_yr_xcnt
    ,NULL nfp_yr_xcnt_s
    ,NULL nfp_qtr_xcnt
    ,NULL nfp_qtr_xcnt_s
    ,NULL nfp_per_xcnt
    ,NULL nfp_per_xcnt_s
    ,NULL nfp_wk_xcnt
    ,NULL nfp_wk_xcnt_s
    ,NULL new_opty_xcnt
    ,NULL new_opty_xcnt_s
    ,NULL won_opty_xcnt
    ,NULL won_opty_xcnt_s
    ,COUNT(lost_opty_amt) lost_opty_xcnt
    ,COUNT(lost_opty_amt_s) lost_opty_xcnt_s
    ,COUNT(no_opty_amt) no_opty_xcnt
    ,COUNT(no_opty_amt_s) no_opty_xcnt_s
    ,NULL cnv_opty_amt_xcnt
    ,NULL cnv_opty_amt_xcnt_s
    ,NULL new_opty_cnt_xcnt
    ,COUNT(CASE WHEN won_opty_cnt IS NULL THEN NULL ELSE 1 END) won_opty_cnt_xcnt
    ,COUNT(CASE WHEN lost_opty_cnt IS NULL THEN NULL ELSE 1 END) lost_opty_cnt_xcnt
    ,COUNT(CASE WHEN no_opty_cnt IS NULL THEN NULL ELSE 1 END) no_opty_cnt_xcnt
    ,NULL cnv_opty_cnt_xcnt
    ,COUNT(CASE WHEN latest_open_opty_cnt IS NULL THEN NULL ELSE 1 END) latest_open_opty_cnt_xcnt
    ,COUNT(*) all_xcnt
  FROM
    bil_bi_op21_g_mv op21
  WHERE
    NOT(won_opty_amt IS NULL AND lost_opty_amt IS NULL AND no_opty_amt IS NULL AND latest_open_opty_cnt IS NULL
        AND won_opty_cnt IS NULL AND lost_opty_cnt IS NULL AND no_opty_cnt IS NULL)
  GROUP BY
     op21.opty_effective_time_id
    ,op21.parent_sales_group_id
    ,op21.sales_group_id
    ,op21.salesrep_id
  UNION ALL
  SELECT
    'CNV' umarker
    ,op21.opty_ld_conversion_time_id effective_time_id
    ,op21.parent_sales_group_id
    ,op21.sales_group_id
    ,op21.salesrep_id
    ,NULL new_opty_amt,NULL new_opty_amt_s
    ,NULL won_opty_amt,NULL won_opty_amt_s
    ,NULL lost_opty_amt,NULL lost_opty_amt_s
    ,NULL no_opty_amt,NULL no_opty_amt_s
    ,SUM(cnv_opty_amt) cnv_opty_amt
    ,SUM(cnv_opty_amt_s) cnv_opty_amt_s
    ,NULL nfp_yr,NULL nfp_yr_s
    ,NULL nfp_qtr,NULL nfp_qtr_s
    ,NULL nfp_per,NULL nfp_per_s
    ,NULL nfp_wk,NULL nfp_wk_s
    ,NULL new_opty_cnt
    ,NULL won_opty_cnt
    ,NULL lost_opty_cnt
    ,NULL no_opty_cnt
    ,SUM(CASE WHEN cnv_opty_cnt IS NULL THEN NULL ELSE 1 END) cnv_opty_cnt
    ,NULL latest_open_opty_cnt
    ,NULL nfp_yr_xcnt
    ,NULL nfp_yr_xcnt_s
    ,NULL nfp_qtr_xcnt
    ,NULL nfp_qtr_xcnt_s
    ,NULL nfp_per_xcnt
    ,NULL nfp_per_xcnt_s
    ,NULL nfp_wk_xcnt
    ,NULL nfp_wk_xcnt_s
    ,NULL new_opty_xcnt
    ,NULL new_opty_xcnt_s
    ,NULL won_opty_xcnt
    ,NULL won_opty_xcnt_s
    ,NULL lost_opty_xcnt
    ,NULL lost_opty_xcnt_s
    ,NULL no_opty_xcnt
    ,NULL no_opty_xcnt_s
    ,COUNT(cnv_opty_amt) cnv_opty_amt_xcnt
    ,COUNT(cnv_opty_amt_s) cnv_opty_amt_xcnt_s
    ,NULL new_opty_cnt_xcnt
    ,NULL won_opty_cnt_xcnt
    ,NULL lost_opty_cnt_xcnt
    ,NULL no_opty_cnt_xcnt
    ,COUNT(CASE WHEN cnv_opty_cnt IS NULL THEN NULL ELSE 1 END) cnv_opty_cnt_xcnt
    ,NULL latest_open_opty_cnt_xcnt
    ,COUNT(*) all_xcnt
  FROM
    bil_bi_op21_g_mv op21
  WHERE
    op21.opty_ld_conversion_time_id IS NOT NULL
  GROUP BY
    op21.opty_ld_conversion_time_id
    ,op21.parent_sales_group_id
    ,op21.sales_group_id
    ,op21.salesrep_id
   UNION ALL
     SELECT
    'WFS' umarker
    ,op21.opty_close_time_id effective_time_id
    ,op21.parent_sales_group_id
    ,op21.sales_group_id
    ,op21.salesrep_id
    ,NULL new_opty_amt
    ,NULL new_opty_amt_s
    ,SUM(won_opty_amt) won_opty_amt
    ,SUM(won_opty_amt_s) won_opty_amt_s
    ,NULL lost_opty_amt
    ,NULL lost_opty_amt_s
    ,NULL no_opty_amt
    ,NULL no_opty_amt_s
    ,NULL cnv_opty_amt
    ,NULL cnv_opty_amt_s
    ,NULL nfp_yr
    ,NULL nfp_yr_s
    ,NULL nfp_qtr
    ,NULL nfp_qtr_s
    ,NULL nfp_per
    ,NULL nfp_per_s
    ,NULL nfp_wk
    ,NULL nfp_wk_s
    ,NULL new_opty_cnt
    ,NULL won_opty_cnt
    ,NULL lost_opty_cnt
    ,NULL no_opty_cnt
    ,NULL cnv_opty_cnt
    ,NULL latest_open_opty_cnt
    ,NULL nfp_yr_xcnt
    ,NULL nfp_yr_xcnt_s
    ,NULL nfp_qtr_xcnt
    ,NULL nfp_qtr_xcnt_s
    ,NULL nfp_per_xcnt
    ,NULL nfp_per_xcnt_s
    ,NULL nfp_wk_xcnt
    ,NULL nfp_wk_xcnt_s
    ,NULL new_opty_xcnt
    ,NULL new_opty_xcnt_s
    ,COUNT(won_opty_amt) won_opty_xcnt
    ,COUNT(won_opty_amt_s) won_opty_xcnt_s
    ,NULL lost_opty_xcnt
    ,NULL lost_opty_xcnt_s
    ,NULL no_opty_xcnt
    ,NULL no_opty_xcnt_s
    ,NULL cnv_opty_amt_xcnt
    ,NULL cnv_opty_amt_xcnt_s
    ,NULL new_opty_cnt_xcnt
    ,NULL won_opty_cnt_xcnt
    ,NULL lost_opty_cnt_xcnt
    ,NULL no_opty_cnt_xcnt
    ,NULL cnv_opty_cnt_xcnt
    ,NULL latest_open_opty_cnt_xcnt
    ,COUNT(*) all_xcnt
  FROM
    bil_bi_op21_g_mv op21
  WHERE
     won_opty_amt IS NOT NULL 
  GROUP BY
     op21.opty_close_time_id
    ,op21.parent_sales_group_id
    ,op21.sales_group_id
    ,op21.salesrep_id