【问题标题】:Replace Asterisk(*) with "anything" in SQL在 SQL 中将 Asterisk(*) 替换为“anything”
【发布时间】:2019-06-07 11:59:54
【问题描述】:

我的数据库中有大量 URL,并希望通过用户定义的字符串过滤它们,格式为 something/*/something,其中* 代表“任何东西”。所以当用户定义checkout/*/complete时,意味着它过滤掉了url之类的:

http://my_url.com/checkout/15/complete
http://my_url.com/checkout/85/complete
http://my_url.com/checkout/something/complete
http://my_url.com/super/checkout/something/complete

等等

如何在 SQL 中做到这一点?还是我应该过滤掉所有结果并使用 PHP 来完成这项工作?

我的 SQL 请求现在是

SELECT * FROM custom_logs WHERE pn='$webPage' AND id IN ( SELECT MAX(id) FROM custom_logs WHERE action_clicked_text LIKE '%{$text_value_active}%' GROUP BY token ) order by action_timestamp desc

这会过滤掉action_clicked_text列中所有带有用户定义文本的日志消息,但使用LIKE语句,该语句不适用于内部*。

【问题讨论】:

    标签: sql regex variables replace


    【解决方案1】:

    你想要like。要么:

    where url like '%checkout/%/complete%'
    

    获取与他的模式匹配的网址。或者:

    where url not like '%checkout/%/complete%'
    

    获取其他网址。

    【讨论】:

    • 非常感谢!没想到这么简单!
    猜你喜欢
    • 1970-01-01
    • 2013-03-13
    • 2019-11-03
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多