SELECT t3.rc, t2.rcs
FROM t2
INNER JOIN t3
ON t3.rc LIKE t2.rcs || '%'
ORDER BY LENGTH(t2.rcs) DESC
FETCH FIRST ROW ONLY
如果t3中有多行,并且希望每行都有最佳匹配,则:
SELECT t3.rc,
t2.rcs
FROM t3
CROSS JOIN LATERAL (
SELECT rcs
FROM t2
WHERE t3.rc LIKE t2.rcs || '%'
ORDER BY LENGTH(t2.rcs) DESC
FETCH FIRST ROW ONLY
) t2
或:
SELECT rc,
rcs
FROM (
SELECT t3.rc,
t2.rcs,
ROW_NUMBER() OVER (PARTITION BY t3.rc ORDER BY LENGTH(t2.rcs) DESC) AS rn
FROM t2
INNER JOIN t3
ON t3.rc LIKE t2.rcs || '%'
)
WHERE rn = 1;
1条答案
按热度按时间yfjy0ee71#
如果只从
t3
中选择了一行,则:如果
t3
中有多行,并且希望每行都有最佳匹配,则:或:
对于您的示例数据,所有输出:
| RC|雷达散射截面|
| - ------|- ------|
| 小行星441|四四一|
fiddle