Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Use la sintaxis SUBSTRING_INDEX en la base de datos MySQL versión 5.5.62

La versión de la base de datos MySQL es 5.5.62

esta es mi mesa

 mysql> SELECT * FROM `dotablenew`; +-----+-------------+ | sID | sStringNew | +-----+-------------+ | 1 | D1080 ARE A | | 2 | D5258 SEG | | 3 | D0749 COR | | 4 | D4278 VAI | | 5 | D2664 PON | +-----+-------------+ 5 rows in set

Necesito esta devolución

 +-------+------+ | sOne | sTwo | +-------+------+ | D1080 | ARE | | D5258 | SEG | | D0749 | COR | | D4278 | VAI | | D2664 | PON | +-------+------+

Y he probado esta solución.

 mysql> SELECT SUBSTRING_INDEX(sStringNew, ' ', 1) AS sOne, SUBSTRING_INDEX(sStringNew, ' ', - 1) AS sTwo FROM `dotablenew`; +-------+------+ | sOne | sTwo | +-------+------+ | D1080 | A | | D5258 | SEG | | D0749 | COR | | D4278 | VAI | | D2664 | PON | +-------+------+ 5 rows in set

Sin éxito porque la primera fila está mal

 +-------+------+ | sOne | sTwo | +-------+------+ | D1080 | A | +-------+------+

Realmente no sé cuántos espacios puede haber en la cadena sStringNew pero siempre necesito extraer los dos primeros elementos de la cadena sStringNew separados por espacios...

¿Cómo resolver esto?

por favor alguna sugerencia

Mi tabla a continuación

 DROP TABLE IF EXISTS `dotablenew`; CREATE TABLE `dotablenew` ( `sID` int(11) NOT NULL AUTO_INCREMENT, `sStringNew` varchar(255) DEFAULT NULL, PRIMARY KEY (`sID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of dotablenew -- ---------------------------- INSERT INTO `dotablenew` VALUES ('1', 'D1080 ARE A'); INSERT INTO `dotablenew` VALUES ('2', 'D5258 SEG'); INSERT INTO `dotablenew` VALUES ('3', 'D0749 COR'); INSERT INTO `dotablenew` VALUES ('4', 'D4278 VAI'); INSERT INTO `dotablenew` VALUES ('5', 'D2664 PON');
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

SELECT sStringNew, SUBSTRING_INDEX(sStringNew, ' ', 1) AS sOne, SUBSTRING_INDEX(SUBSTRING_INDEX(sStringNew, ' ', 2), ' ', -1) AS sTwo FROM `dotablenew`
over 4 years ago · Santiago Trujillo Report

0

Prueba esto:

 SELECT SUBSTRING_INDEX(sStringNew, ' ', 1) AS sOne, REVERSE(SUBSTRING_INDEX(REVERSE(SUBSTRING_INDEX(sStringNew, ' ', 2)), ' ', 1)) AS sTwo FROM `dotablenew`
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!