我目前有2个视图:t_sdet_part
和t_sdet_part_all
。 t_sdet_part
正在从视图table_mv
提取数据,并创建table_mv
中尚不存在的行。然后,将创建的数据合并到另一个视图中以显示所有记录(t_sdet_part_all
)。下面是我当前的代码:
-- view created: t_sdet_part
WITH v as (
SELECT v.*
FROM table_mv v
)
SELECT d.s_date, ig.part_no, ig.i_group, l.s_level, ig.p_category,
COALESCE(v.qty_ordered, 0) as qty_ordered
FROM (SELECT DISTINCT s_date FROM v) d CROSS JOIN
(SELECT DISTINCT part_no, i_group, p_category FROM v) ig CROSS JOIN
(SELECT '80' as s_level FROM DUAL UNION ALL
SELECT '81' FROM DUAL UNION ALL
SELECT '95' FROM DUAL UNION ALL
SELECT '101' FROM DUAL UNION ALL
SELECT '100' FROM DUAL UNION ALL
SELECT 'Late' FROM DUAL
) l LEFT JOIN
v
ON v.s_date = d.s_date AND v.part_no = ig.part_no AND
v.i_group = ig.i_group AND v.s_level = l.s_level
ORDER BY s_date, part_no, i_group,
DECODE(s_level, '80', 1, '81', 2, '95', 3, '101', 4, '100', 5, 'Late', 6)
-- view created t_sdet_part_all
SELECT DISTINCT
t.s_date,
t.part_no,
t.i_group,
t.s_level,
t.p_category,
t.qty_ordered,
v.bucket,
v.relief_amt,
v.extreme_amt,
v.curr_mth_note,
v.carryover_note
FROM
t_sdet_part t
LEFT JOIN table_mv v ON t.s_date = v.s_date
AND t.part_no = v.part_no
ORDER BY
s_date,
part_no,
i_group,
DECODE(s_level, '80', 1, '81', 2, '95', 3, '101', 4, '100', 5, 'Late', 6)
它们都从table_mv
中提取和合并数据。我正在尝试找到一种方法(如果可能的话)组合以下两个文件,因此我只需要创建一个新视图即可,而不是2。