我在 Snowflake 中作業,給定表和列中的一些 ID 用分號分隔。盡管有這個分隔符,表仍然應該被加入。任何連接表的嘗試通常都會遇到某種錯誤。
下面我有一個我試圖做的例子。
table_A table_B
---------- ---------- ---------- ----------
| some_id | F_Name | | some_id | L_Name |
---------- ---------- ---------- ----------
| 12345 | John | |12345;4321| Doe |
---------- ---------- ---------- ----------
Attempted SQL Statement
select table_A.some_id, table_A.F_name, table_B.L_Name
from table_A
left join table_B on table_A.some_id like '%'||table_B.some_id||'%'
此特定問題的來源已顯示在此處,但似乎不起作用。可能無法以這種特定方式進行連接。

uj5u.com熱心網友回復:
如果您使用 CTE 將第二個表展平,然后過濾掉重復項
WITH expand AS (
SELECT
f.seq as seq,
f.index as index
f.value as join_token
t.l_name
FROM table_b t,
lateral split_to_table(t.some_id, ';') f
)
SELECT
a.some_id,
a.f_name,
f.l_name
FROM table_a AS a
LEFT JOIN expand AS f
ON a.some_id = f.join_token
QUALIFY row_number() over (partition by f.seq ORDER BY f.index) == 1
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/338399.html
上一篇:片段-帶有DatePickerDialog片段的EditText
下一篇:如何加入并非全部可用的行?
