【问题标题】:Search in a column sql by first and last characters按第一个和最后一个字符在 sql 列中搜索
【发布时间】:2019-06-21 16:24:28
【问题描述】:

在我的数据表中我有一列reference,该列的数据由categorie + idproduct + idmaker 示例:

reference      | categorie + idproduct + idmaker
---------------|--------------------
cat48934547814 | [cat48][934][547814]
cat55548451412 | [cat55][548][451412] 
cat48548547814 | [cat48][548][547814]

我想搜索所有引用以cat48 开头并以547814 结尾的产品。

谢谢

【问题讨论】:

    标签: php psql postgresql-9.4


    【解决方案1】:

    你可以用一对像

    select  * 
    from my_table  
    where reference like 'cat48%' 
    and reference like '%547814' 
    

    或带有子字符串

    select  * 
    from my_table  
    where left(reference, 5)  = 'cat48' 
    and right(reference ,6) = '547814'
    

    【讨论】:

    • 谢谢,我以为我在使用子字符串时会变得更好 :)
    • 谢谢,由于性能原因,不建议使用“like”;)
    猜你喜欢
    • 2013-02-14
    • 1970-01-01
    • 2022-12-09
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 1970-01-01
    • 2014-07-13
    相关资源
    最近更新 更多