You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MS-SQL如何用LIKE匹配以RI开头后接指定字符的字符串

用LIKE实现指定前缀筛选的SQL写法

你可以通过将每个目标前缀搭配空格和通配符%,用OR连接来实现需求,具体SQL语句如下:

WHERE A.[pa-smart-comment] LIKE 'RIRV %'
   OR A.[pa-smart-comment] LIKE 'RIUI %'
   OR A.[pa-smart-comment] LIKE 'RIRI %'
   OR A.[pa-smart-comment] LIKE 'RICJ %'
   OR A.[pa-smart-comment] LIKE 'RIRE %'
   OR A.[pa-smart-comment] LIKE 'RIRF %'
   OR A.[pa-smart-comment] LIKE 'RIAW %'
   OR A.[pa-smart-comment] LIKE 'RIAS %'
   OR A.[pa-smart-comment] LIKE 'RINA %'

补充说明:

  • %是SQL标准通配符,代表任意长度的任意字符(包括空字符),确保匹配以指定前缀加空格开头的所有记录。
  • 原SUBSTRING写法需要先截取字符串再匹配,无法利用列上的前缀索引;而这种LIKE前缀匹配的方式,若[pa-smart-comment]列存在非聚集索引,数据库可直接通过索引扫描筛选数据,大幅提升执行效率。

内容的提问来源于stack exchange,提问作者MCP_infiltrator

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 02:07:18