0

I know, this could easly be done using PHP, but just curious,

How could I explode on mail field to select the value from alias column with the first exploded part by @?

Current:

+-------+-----------------------------------------+
| alias | mail                                    |
+-------+-----------------------------------------+
|       | user.one@gmail.com                      |
|       | user.two.foo@gmail.com                  |
+-------+-----------------------------------------+

Desired:

+-------+------------------------------------------------+
| alias        | mail                                    |
+-------+------------------------------------------------+
| user.one     | user.one@gmail.com                      |
| user.two.foo | user.two.foo@gmail.com                  |
+-------+------------------------------------------------+

In pseudo code would be like

update tablename set tablename.alias = explode('@', tablename.mail)[0];
4

1 回答 1

1

在 MySQL 中,您可以使用substring_index()

update t
    set alias = substring_index(t.mail, '@', 1);
于 2018-02-13T18:35:50.817 回答