0

I have a database where I have the following contact table in the image:

idservicio idcliente nombre contacto telefono
76543 2 maria perez 123456
76543 2 miguel o 765433
98765 1 sara perez 876658
98765 1 jose o 987665
98765 1 orlando 876540
76543 3 jack 123456
76543 3 ana 654324
76543 3 kevin 954326

and I want to perform a query where the output is as follows:

idservicio idcliente telefono 1 telefono 2 telefono 3
76543 2 123456 765433
98765 1 876658 987665 876540
76543 3 123456 654324 954326

In sql server I did it with row_number over partition by , how can I do it in mysql, I have version 5.7.36

cudris
  • 23
  • 5
  • MySQL do have row_number(). https://www.mysqltutorial.org/mysql-window-functions/mysql-row_number-function/ – Roshan Nuvvula Jun 28 '22 at 03:14
  • [Please do not upload images of code/data/errors when asking a question.](//meta.stackoverflow.com/q/285551) This also applies to database schemas, sample data and desired output. – Ken White Jun 28 '22 at 03:16
  • @TimBiegeleisen I included the tables as text – cudris Jun 28 '22 at 03:22
  • @cudris In fact, MySQL 8+ supports `ROW_NUMBER`. So your current SQL Server query should also run on newer versions of MySQL. – Tim Biegeleisen Jun 28 '22 at 03:23
  • @TimBiegeleisen I have mysql version 5.7.36 – cudris Jun 28 '22 at 03:27
  • You can generate pseudo-column with something like this ```select sum(1) over (order by nombre_contacto,telefono),t.* from test_tab t;``` – Pankaj Jun 28 '22 at 04:16

0 Answers0