mysql-使用DISTINCT的REGEXP_REPLACE
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mysql-使用DISTINCT的REGEXP_REPLACE,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1445字,纯文字阅读大概需要3分钟。
内容图文
![mysql-使用DISTINCT的REGEXP_REPLACE](/upload/InfoBanner/zyjiaocheng/880/3ebab54bccf44d8b9d90998476a9c804.jpg)
我正在尝试使用REGEXP_REPLACE与众不同,并返回0行.
我已经在MySQLP v8.0中创建了一个测试表
CREATE TABLE phone(
id serial primary key,
phone_number char(25));
INSERT INTO phone (phone_number)
VALUES ('(423) 330-9999');
INSERT INTO phone (phone_number)
VALUES ('(423)3309999');
INSERT INTO phone (phone_number)
VALUES ('423-330-1111)');
INSERT INTO phone (phone_number)
VALUES ('1-423-330-6666');
INSERT INTO phone (phone_number)
VALUES ('1A423*330*1111');
INSERT INTO phone (phone_number)
VALUES ('5553301111');
– 然后
select
REGEXP_REPLACE(phone_number, '[^0-9]', '',1, 0, 'm') as clean_phone
from phone
—工作正常->
clean_phone
4233309999
4233309999
4233301111
14233306666
14233301111
5553301111
—计数
select
count(REGEXP_REPLACE(phone_number, '[^0-9]', '',1, 0, 'm')) as
clean_phone
from phone
—工作正常->
clean_phone
6
-独特的clean_phone
select
distinct(REGEXP_REPLACE(phone_number, '[^0-9]', '',1, 0, 'm')) as
clean_phone
from phone
—返回空->
clean_phone
我不明白为什么区分不起作用?
解决方法:
Distinct不是函数,因此您不需要distinct(),而仅需要distinct
select distinct REGEXP_REPLACE(phone_number, '[^0-9]', '',1, 0, 'm') as
clean_phone
from phone
.
select distinct clear_phone from(
select REGEXP_REPLACE(phone_number, '[^0-9]', '',1, 0, 'm') clear_phone
from phone ) t
如果错误仍然存??在,您可以尝试使用虚拟表的插入/选择
insert into dummy_table(clear_phone)
select REGEXP_REPLACE(phone_number, '[^0-9]', '',1, 0, 'm')
from phone;
select distinct clear_phone from dummy_table;
内容总结
以上是互联网集市为您收集整理的mysql-使用DISTINCT的REGEXP_REPLACE全部内容,希望文章能够帮你解决mysql-使用DISTINCT的REGEXP_REPLACE所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。