Insert and Select in MySQL

0

I have a small problem with a database ... since what I need is to be able to mix that data. Currently this is my BD

However, I need you to stay like this:

In theory I must add the MATRIX with (intertidal) and (subtidal) ... the issue is that they are more than 1000 records, so doing it manually would take me days ...

If someone could help me with a Script, it would be ideal.

Thanks

    
asked by Juan Pablo 25.10.2018 в 22:09
source

1 answer

0

I do not have a MyQL database at hand, but in general terms a proposal would be to build a cursor to go through the table and for each of the records, concatenate the additional descriptions that you need and make the two inserts:

DECLARE finaliza INT DEFAULT FALSE;
DECLARE nuevaMatriz varchar(128);
DECLARE idEnsayo int;
DECLARE analisis varchar(64);
DECLARE matriz varchar(128);
...
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finaliza = TRUE;
DECLARE micursor CURSOR FOR SELECT idEnsayo ,analisis, matriz, metodologias, laboratorio FROM mitabla;

  OPEN micursor;          
  read_loop: LOOP
    FETCH micursor INTO idEnsayo, analisis, matriz;

    IF finaliza THEN
      LEAVE read_loop;
    END IF;

    select nuevaMatriz = concat(matriz,' (Intermareal)')
    insert into mitabla values (idEnsayo, analisis, nuevaMatriz);

    select nuevaMatriz = concat(matriz,' (Submareal)')
    insert into mitabla values (idEnsayo, analisis, nuevaMatriz);

  END LOOP;

  CLOSE micursor;
    
answered by 26.10.2018 в 01:12