我有一个表“cosings”,带有“CAS_No”列和“INCI_name”列。另一个表是一个以分号分隔值ALIAS为“semicolon_separated”的表。 我想匹配“INCI_name”和“semicolon_separated”并获得“CAS_No”。
SELECT
"CAS_No"
FROM
cosings
RIGHT OUTER JOIN
(SELECT
TRIM(unnest(string_to_array(ingredients, ';'))) AS semicolon_separated
FROM
products
WHERE
id = 1
) AS ing_table
ON cosings."INCI_name" = ing_table.semicolon_separated;
我获得了正确的行数,但所有行都是空的。
产品表:
id | ingredients
1 chemical_1 ; chemical_2; chemical_3
2 compound_5; compound_10
Cosing Table:
INCI_name | CAS_No
chemical_1 111
chemical_2 222
compound_5 555
如果我从Product表中选择id = 1,我应该得到:
CAS_No
111
222