【发布时间】:2016-03-22 14:54:41
【问题描述】:
我想使用子字符串列表作为LIKE 子句的值。
考虑下表:
菌株
id name
-------------------------------------------------------
562 B6;129 (Bnip3 KO)
563 B6;129 (BNIP3 Wt) [pregnant]
564 B6;129 (BNIP3 Wt) [older than 21 days]
720 BALB/C T(x:11)38H (T38H)
721 BALB/C [older than 21 days]
链接 (l)
id protocol_id strain_id
-------------------------------------------------------
1 61846 563
2 13487 564
3 79465 721
4 41699 720
动物(一)
id group_id strain_id
-------------------------------------------------------
24 9666 563
25 9666 720
通常我会提供一个我尝试过的查询,但这次我什么都没有。相反,让我分解一下我需要做的步骤:
- 从同一
group_id下的所有动物的菌株名称中获取子字符串列表。- 为了得到子字符串,我想要
(和)里面的字符串 - 类似
SELECT /* get the list of substrings */ FROM animals a LEFT JOIN strains s ON s.id = a.strain_id WHERE a.group_id = 9666 - 在本例中,我需要以下列表:
(BNIP3 Wt)和(T38H) - 如果
(和)中包含多个值,则使用最后一个
- 为了得到子字符串,我想要
- 使用上述
LIKE子句的结果列表来获取protocol_id的列表,其菌株名称包含子字符串。
我对解决方案的想法
SELECT l.protocol_id
FROM links l
LEFT JOIN strains s
ON s.id = l.strain_id
WHERE s.name LIKE (/* put the list here with the % for wildcards */)
我想要得到的最终结果如下:
protocol_id
------------------------------
61846
13487
41699
【问题讨论】: