gpt4 book ai didi

mysql - 从通过匹配 SQL 中的正则表达式生成的列中获取唯一条目

转载 作者:行者123 更新时间:2023-11-29 02:53:50 29 4
gpt4 key购买 nike

我有一个表,我正在使用它来查询并获取与正则表达式匹配的一列 (\/.+\/\?)

结果列的内容如下:/Anything here/?
示例输出:

\abc\cdf\?....
\ab\?....
\abc\cdf\?....
\sb\?....

'....' 可以是任何内容

我想要的期望结果是 \? 之前的唯一值,这样具有重复正则表达式匹配内容的行只显示一次,就像这里一样 (\abc\cdf\?....显示两次而不是一次)

\abc\cdf\?....
\ab\?....
\sb\?....

\abc\cdf\?
\ab\?
\sb\?

我看了很多,但找不到任何东西,在 oracle 中有 regexp_substr 但它在 SQL 中不起作用。

如果有人可以帮助我进行 sql 查询,那就太棒了。

最佳答案

如果你想要最后一个 \ 之前的所有内容,那么你可以使用 substring_index() 和一些字符串操作:

select substring_index(col, '\\',
length(col) - length(replace(col, '\\', ''))
) as firstpart,
count(*)
from table t
group by substring_index(col, '\\',
length(col) - length(replace(col, '\\', ''))
);

关于mysql - 从通过匹配 SQL 中的正则表达式生成的列中获取唯一条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32782147/

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