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

219
Views
Uso de expresiones regulares en MySql

Necesito escribir una consulta sql que recupere y haga coincidir los registros de una tabla con las siguientes columnas;

 first_name, second_name, attribute

El objetivo es escribir una consulta, que coincida solo con aquellos registros donde el attribute de la columna tiene el siguiente formato;

 <one or more arbitrary character>%<first name>_<second name>%<zero or more arbitrary characters>

Cabe señalar que incluso las mayúsculas y minúsculas coinciden con first_name y second_name . La salida de muestra debería verse así;

 first_name second_name attribute Vicenta Kravitz 0%Vicenta_Kravitz% Shayne Dahlquist 0R0V331K8Q7ypBi4Az3B6Nm0jCqUk%Shayne_Dahlquist%46E3O0u7t7 Mikel Kravitz PBX86iw1Ied87Z9OarE6sdSLdt%Mikel_Kravitz%W73XOY9YaOgi060r2x12D2EmD

Como puede ver, los casos de las letras en first_name y last_name también coinciden. Aquí está mi intento;

 SELECT first_name, second_name, attribute FROM table WHERE attribute REGEXP '^.+ CONCAT('%',binary(first_name),'_',binary(last_name),'%').*' ORDER BY attribute;

Dado que la coincidencia de casos es un requisito, creo que la función binary() puede ayudar. Pero recibo el siguiente error de sintaxis;

 ERROR 1064 (42000) at line 35: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '_',binary(last_name),'%').*' ORDER BY attribute; END' at line 10

Mirar el manual no está ayudando mucho. ¿Puedo obtener algunos comentarios sobre lo que puede estar fallando aquí? Gracias.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tienes que concatenar la cadena de registro del agujero como

 CREATE TABLE Table1 (`first_name` varchar(7), `second_name` varchar(9), `attribute` varchar(66)) ; INSERT INTO Table1 (`first_name`, `second_name`, `attribute`) VALUES ('Vicenta', 'Kravitz', '0%Vicenta_Kravitz%'), ('Shayne', 'Dahlquist', '0R0V331K8Q7ypBi4Az3B6Nm0jCqUk%Shayne_Dahlquist%46E3O0u7t7'), ('Mikel', 'Kravitz', 'PBX86iw1Ied87Z9OarE6sdSLdt%Mikel_Kravitz%W73XOY9YaOgi060r2x12D2EmD') ;
 SELECT first_name, second_name, attribute FROM Table1 WHERE attribute REGEXP CONCAT('^.+%',binary(first_name),'_',binary(second_name),'%.*') ORDER BY attribute;
nombre | segundo_nombre | atributo                                                         
:--------- | :----------- | :------------------------------------------------- ----------------
Vicenta | Kravitz | 0%Vicenta_Kravitz%                                                
Shayne | Dahlquist | 0R0V331K8Q7ypBi4Az3B6Nm0jCqUk%Shayne_Dahlquist%46E3O0u7t7         
Mikel | Kravitz | PBX86iw1Ied87Z9OarE6sdSLdt%Mikel_Kravitz%W73XOY9YaOgi060r2x12D2EmD

db<>violín aquí

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!