欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql的group_concat方法和正则(REGEXP)的结合使用

程序员文章站 2022-05-31 22:20:28
...
select (select group_concat(a.name) from addressbook a where a.mobile in (s.receive_mobiles)) names,s.receive_mobiles from sms_send_record s where id=77;

+-------+-------------------------------------+
| names | receive_mobiles                     |
+-------+-------------------------------------+
| NULL  | 13825722737,13375006095,13875005239 |
+-------+-------------------------------------+
1 row in set

select (select group_concat(a.name) from addressbook a where a.mobile REGEXP replace(s.receive_mobiles,',','|')) names,s.receive_mobiles from sms_send_record s where id=77;

+----------------------+-------------------------------------+
| names                | receive_mobiles                     |
+----------------------+-------------------------------------+
| 张款民,宋里露,王  华 | 13825722737,13375006095,13875005239 |
+----------------------+-------------------------------------+
1 row in set