你尋找的是這樣的:
WITH RECURSIVE x AS (
-- choose first level - without more connections
SELECT id, id AS full_id, 1 AS level
FROM foo
WHERE NOT EXISTS (
SELECT 1
FROM foo AS foo2
WHERE foo.id != foo2.id
AND foo.id[1] = foo2.id[array_length(foo2.id, 1)])
-- add tail
UNION ALL
SELECT x.id, x.full_id || foo.id[2:array_length(foo.id, 1)], level + 1
FROM x
JOIN foo ON (
foo.id != x.id
AND foo.id[1] = x.full_id[array_length(x.full_id, 1)]
AND array_length(foo.id, 1) != 1)
), z AS (
-- looks for maximum length
SELECT max(level) OVER (PARTITION BY id), * FROM x
)
-- choose only with maximum length
SELECT full_id FROM z WHERE max = level
所以他們加入只有對最後INT流入排滿足? –
是的,確切地說,我們將每行的最後一個int與其他行中的第一個int進行匹配 – pastDexter