【发布时间】:2020-09-20 09:00:07
【问题描述】:
我在 postgres 11.0 中有下表
| col1 | col2 | col3 | col4 |
|---|---|---|---|
| NCT00001723 | 4894402 | xenical (orlistat)capsules | xenical |
| NCT00001724 | 4894403 | xenical (orlistat)capsules | orlistat |
| NCT00001725 | 4894404 | capsules | capsules |
| NCT00001726 | 4894405 | insulin | ins |
我想过滤以上行,以便 col3 = col4 或 col3 的确切内容应包含在 col4 中。
想要的输出是:
| col1 | col2 | col3 | col4 |
|---|---|---|---|
| NCT00001723 | 4894402 | xenical (orlistat)capsules | xenical |
| NCT00001724 | 4894403 | xenical (orlistat)capsules | orlistat |
| NCT00001725 | 4894404 | capsules | capsules |
我正在尝试下面的查询来获得这个输出。
SELECT
*
FROM
table
where col3 = col4 or --exact match
regexp_matches(col3, '(.*).*\(') = col4 or --match content before brackets
regexp_matches(col3, '.*\(.*\).*') = col4 --match content in brackets
这里的任何建议都会很有帮助。谢谢
【问题讨论】:
标签: sql regex postgresql select where-clause