sql - 如何在 SQL 中使用选择查询来查找仅包含 6 个随机数的电子邮件地址列表?
问题描述
我目前正在寻找一种使用 SQL 查询的方法,以便在我们的数据库中查找所有电子邮件地址的列表,其中只有 6 个随机数,然后是“@gmail.com”。
例子:
email
----------
123456@gmail.com
324522@gmail.com
这是我尝试过的:
select email
from customers
where email Not like '%^[0-9]%'
当我运行它时,所有电子邮件都会出现,即使是那些没有任何数字的电子邮件。
select email,
SPLIT_PART(email, '@',1) as username,
SPLIT_PART(email, '@',2) as domain,
(case when username not like '%^[0-9]%' then 'Incorrect' else 'Correct' End) as format
from customers
where domain = 'gmail.com'
and format = 'Correct'
我也尝试过,对于所有电子邮件,即使它们中有数字,它们也会显示为不正确。
似乎无法识别列中的数字,我不确定如何解决。列格式为 Varchar
解决方案
我与 Mode Analytics 交谈,结果发现我的数据库是 Redshift,这就是我能够完成这项工作的方式:
select email
from customers
where email similar to '[0-9]{6}@gmail.com'
感谢大家的帮助!
推荐阅读
- php - 如何在 php 中将 JSON 对象的集合转换为 YAML
- elasticsearch - 弹性搜索:如果找不到文档,有什么方法可以忽略脚本?
- reactjs - 我想将 iam 角色凭据的会话持续时间更改为 12 小时
- python - 尝试训练 TensorFlow 模型时如何修复 InvalidArgument 错误?
- ssh - 如何区分证书,使用同一个Ca时,
- localization - 带有数据库的 Laravel 语言环境
- r - 如何从 R 中的字符向量的每个部分中消除前 x 个元素?
- leaflet - 如何将具有设定尺寸的自定义多边形形状添加到 Leaflet Draw 控件?
- java - 在 Spring Batch 中如何将新值放入 JobParameters 如果从命令行找不到值,则在运行时添加
- java - Java Spark Naive Bayes - 预测未来时间戳