MySQL 查询从 email-id 获取域名?
mysqlmysqli database更新于 2025/5/15 13:32:17
为此使用 SUBSTRING_INDEX()。让我们首先创建一个表 −
mysql> create table DemoTable -> ( -> UserMailId varchar(100) -> ); Query OK, 0 rows affected (0.68 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('John@gmail.com');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable values('Carol94844@yahoo.com');
Query OK, 1 row affected (0.25 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
输出
这将产生以下输出 −
+----------------------+ | UserMailId | +----------------------+ | John@gmail.com | | Carol94844@yahoo.com | +----------------------+ 2 rows in set (0.00 sec)
以下是获取域名的查询 −
mysql> select substring_index(UserMailId,'@',-1) as RightSideValue from DemoTable;
输出
这将产生以下输出 −
+----------------+ | RightSideValue | +----------------+ | gmail.com | | yahoo.com | +----------------+ 2 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

