我在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
这里的任何建议都会非常有帮助。谢谢
如果我正确地跟随了您,则可以使用单词边界转义\y
:
\y
:仅在单词的开头或结尾匹配
在您的查询中:
select * from mytable where col3 ~ ('\y' || col4 || '\y')
col1 | col2 | col3 | col4 :---------- | ------:| :------------------------- | :------- NCT00001723 | 4894402 | 塞尼胶囊(orlistat)| Xenical NCT00001724 | 4894403 | 塞尼胶囊(orlistat)| 奥利司他 NCT00001725 | 4894404 | 胶囊| 胶囊
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句