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

如何筛选同时包含整数与字符串的auditorium记录?

解决方案

要精准筛选auditorium字段同时包含数字与字符串的记录,需要替换原语句中auditorium like "% %"的模糊匹配条件,改用正则或模式匹配来同时校验数字和字符串的存在。以下是不同主流数据库的修改方案:

MySQL/MariaDB 版本

select 
    distinct auditorium, 
    circuit_name 
from table_name
where 
    date >= current_date() 
    and 
    auditorium regexp '[0-9]' 
    and 
    auditorium regexp '[^0-9 ]'
order by 
    circuit_name;
  • auditorium regexp '[0-9]':确保字段里至少有一个数字
  • auditorium regexp '[^0-9 ]':确保字段里至少有一个非数字、非空格的字符(即有效字符串内容)

PostgreSQL 版本

select 
    distinct auditorium, 
    circuit_name 
from table_name
where 
    date >= current_date() 
    and 
    auditorium ~ '[0-9]' 
    and 
    auditorium ~ '[^0-9 ]'
order by 
    circuit_name;

PostgreSQL 使用~作为正则匹配运算符,逻辑和MySQL一致。

SQL Server 版本

select 
    distinct auditorium, 
    circuit_name 
from table_name
where 
    date >= current_date() 
    and 
    PATINDEX('%[0-9]%', auditorium) > 0 
    and 
    PATINDEX('%[^0-9 ]%', auditorium) > 0
order by 
    circuit_name;

用PATINDEX函数检测模式是否存在,返回大于0的值即表示匹配成功。

效果验证

用你的样本数据测试时:

  • 会保留8 XP、Reserved 20、15 Reserved、Drive In 91.9 FM这些同时包含数字和字符串的记录
  • 自动排除Apple Xtreme、Atmos Reserved这类无数字的纯字符串组合,完全符合你的期望输出。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 02:22:40