If you want to use "formatting" directly on SQL
, you can try the following:
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(seu_campo, '.', 2), '.', -1) as dominio FROM sua_tabela
Just replace the suggestive names with their values. As you have not provided more details of the language used, there is no other way to provide.
The use of SUBSTRING_INDEX
is quite simple.
You provide a string, delimiter and quantity(Count).
In your case, let’s take as a basis the value www.dominio.com.br
, follow the examples:
SUBSTRING_INDEX('www.dominio.com.br', '.', 2) => 'www.dominio';
//Números positivos, tudo o que estiver a esquerda do "delimitador final" (contando da esquerda) é retornado.
SUBSTRING_INDEX('www.dominio.com.br', '.', -2) => 'com.br';
//Números negativos, tudo o que estiver a direita do "delimitador final" (contando da direita) é retornado
Having the above results, we will apply your case:
SUBSTRING_INDEX(SUBSTRING_INDEX('www.dominio.com.br', '.', 2), '.', -1) => 'dominio';
As we know the first expression to be executed will return www.dominio
, we use the expression again and take the first position on the right (for this we use the negative value -1), which in the case returns dominio
.
I hope I have been clear in the explanation. Any question or suggestion for improvement to the answer, please feel free to request.
Sources/References:
Split value from one field to two
Documentation
If you want to use "editing" directly in SQL, you can try the following:
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(seu_campo, '.', 2), '.', -1) as dominio FROM sua_tabela
, only replace the suggestive names by their values. As you have not provided more details of the language used, there is no other way to provide.– Rafael Withoeft
Opa, exactly what I need, the "seu_campo" I will exchange here for ORIGEM_PESSOA, except that DOMINIO is a field of the table and can have N values (dominioX, dominioZ, etc.). How can I do it? Thanks @Rafaelwithoeft
– Eduardo Correia
The
as dominio
is only an alias, can be replaced by the name you wish... was that what was in doubt? The fieldORIGEM_PESSOA
is the one described in your question that has the valuewww.dominio.com.br
?– Rafael Withoeft
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(origem_pessoa, '.', 2), '.', -1) FROM person, that’s how it got what I need, this way it’s only returning the domain without www, . with or with. Thanks!! @Rafaelwithoeft
– Eduardo Correia
So it worked right? :)
– Rafael Withoeft
Yes! Solved thank you very much (by the way I mark SOLVED here on Stack?)
– Eduardo Correia
Only in answers... can I assemble one for you
– Rafael Withoeft
Please provided that you (or whoever helped) is "decorated" heheh
– Eduardo Correia