gpt4 book ai didi

postgresql - 使用正则表达式的 SQL sql 查询

转载 作者:行者123 更新时间:2023-11-29 13:47:28 32 4
gpt4 key购买 nike

我有像这样的专栏

Column1   column 2
Audy. 123
Baza.z. 675
Sco,da@. 432

我在努力

  1. 从表中选择 column2 where lower(column1)='audy';

  2. select column2 from table where lower(column1) regexp'[.,]' ='audy';

我需要使用 sql 或 postgre sql 的列数据,其中没有特殊字符,并且应该只从 where 条件中获取正则表达式。

最佳答案

您可以使用 regex_replace :

select  column2 
from table
where regexp_replace(lower(column1), '\W', '', 'g') = 'audy'

正则表达式 \W 匹配任何非字母或数字的字符。标志 'g'(全局)表示删除所有匹配项,而不仅仅是第一个匹配项。

关于postgresql - 使用正则表达式的 SQL sql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46056191/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com