Comment sélectionner la première lettre de chaque mot d'une cellule de table dans MySQL?

StackOverflow https://stackoverflow.com/questions/8313154

  •  25-10-2019
  •  | 
  •  

Question

Comment puis-je sélectionner la première lettre de chaque mot dans MySQL en utilisant une requête?

ce tableau

+----+----------------------------+
| id | str                        |
+----+----------------------------+
|  1 | Hello my name is MCEmperor |
|  2 | How are you doing?         |
+----+----------------------------+

renverrait

+----+----------------------------+
| id | str                        |
+----+----------------------------+
|  1 | HmniM                      |
|  2 | Hayd                       |
+----+----------------------------+

Je suppose que c'est quelque chose avec SUBSTRING et LOCATE et peut-être je besoin d'une boucle (pour trouver tous les espaces ou quelque chose) ...

Est-il possible dans une requête? Comment dois-je faire?

Était-ce utile?

La solution

Maybe you could simply split by space? Use this stored proc : http://forums.mysql.com/read.php?60,78776,148332#msg-148332

You can then retrieve the first letters of each word and use GROUP_CONCAT in a GROUP BY Id to put the letters back into one line per initial text.

Autres conseils

What you're looking for is a WHERE clause that matches only part of the data in the cell. You can do that like so:

SELECT str 
from (table name) 
WHERE str LIKE 'H%'
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top