对 Oracle 中的公共值进行分组
Grouping the common values in Oracle
我有一个 table 样本值如下
在此table中,Col1 中的所有值都将在Col2 中具有其支持值。值 A1 和 A2 就像主值一样,它们永远不会出现在 Col2 中。我需要在如下所示的新列中显示此主值的输出
在 Oracle SQL 中实现此目标的最佳方法是什么?
看起来像分层查询:
SQL> select connect_by_root t.col1 as main,
2 t.col1,
3 t.col2
4 from test t
5 start with t.col1 in ('A1', 'A2')
6 connect by t.col1 = prior t.col2
7 order by main, t.col1, t.col2;
MAIN COL1 COL2
----- ----- -----
A1 A1 B1
A1 A1 B2
A1 A1 B3
A1 B1 C1
A1 B2 C2
A1 C1 D1
A2 A2 E1
A2 A2 E2
A2 E1 F1
A2 E1 F2
10 rows selected.
SQL>
我有一个 table 样本值如下
在此table中,Col1 中的所有值都将在Col2 中具有其支持值。值 A1 和 A2 就像主值一样,它们永远不会出现在 Col2 中。我需要在如下所示的新列中显示此主值的输出
在 Oracle SQL 中实现此目标的最佳方法是什么?
看起来像分层查询:
SQL> select connect_by_root t.col1 as main,
2 t.col1,
3 t.col2
4 from test t
5 start with t.col1 in ('A1', 'A2')
6 connect by t.col1 = prior t.col2
7 order by main, t.col1, t.col2;
MAIN COL1 COL2
----- ----- -----
A1 A1 B1
A1 A1 B2
A1 A1 B3
A1 B1 C1
A1 B2 C2
A1 C1 D1
A2 A2 E1
A2 A2 E2
A2 E1 F1
A2 E1 F2
10 rows selected.
SQL>