SUBSTRING_INDEX,带有多个定界符 [英] SUBSTRING_INDEX with multiple delimiters

查看:202
本文介绍了SUBSTRING_INDEX,带有多个定界符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从放置在数据库中的url中删除一些信息.我正在使用此查询:

I am trying to remove some information off urls that are placed into my database. I have this query that I am using:

Select substring_index(refurl,'?gclid',1) as refurl, Count(*)
from leads
group by substring_index(refurl,'?gclid',1)

但是对于分隔符,我确实需要删除这两个:

But for the delimiter I really need to take off both of these:

?gclid or &gclid 

是否可以通过在子字符串中执行OR语句来完成此操作,或者完全不同于此操作吗?

Is this possible by doing an OR statement within the substring or is it something completely different to get this done?

推荐答案

使用IF

SELECT SUBSTRING_INDEX(refurl, IF(LOCATE('?gclid', refurl), '?gclid', '&gclid'), 1) AS refurl, ...

这篇关于SUBSTRING_INDEX,带有多个定界符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆