Home > Mobile >  How can I insert random values in the rest of the columns
How can I insert random values in the rest of the columns

Time:03-18

Im haveing this table and is felling with datas from another table and i need the rest to be random inserted form 0-10 interval

CREATE TABLE IF NOT EXISTS `Spital`.`Chirurgie` (
      `ID Persoanl` INT NOT NULL,
      `Doctor` VARCHAR(45) NULL,
      `Ore` VARCHAR(45) NULL,
      `Pacienti tratati` VARCHAR(45) NULL,
      `ID Produse` INT NULL,
      `Denumire` VARCHAR(45) NULL,
      `Cantitate` INT NULL,
      `IdDepartament` INT NULL,
      PRIMARY KEY (`ID Persoanl`),



INSERT INTO `spital`.`chirurgie`
            (`ID Persoanl`,
             `Doctor`,
             `Ore`)
SELECT `ID Angajare`,
       `Asistent/Medic`,
       `Ore lucrate`
FROM   `spital`.`personal` 
where `Specializare` like '%Chirurgie%' and `Asistent/Medic`like '%Medic%' ;

This is the inseration code that im using for auto fill the values from the other table.

CodePudding user response:

you following query

INSERT INTO `spital`.`chirurgie`
            (`ID Persoanl`,
             `Doctor`,
             `Ore`,
             `Pacienti tratati`,
             `ID Produse`,
             `Cantitate`)
SELECT `ID Angajare`,
       `Asistent/Medic`,
       `Ore lucrate`,
        floor(rand()*10) 1 as `Pacienti tratati`,
        floor(rand()*10) 1 as `ID Produse`,
        floor(rand()*10) 1 as  `Cantitate`
FROM   `spital`.`personal` 
where `Specializare` like '%Chirurgie%' and `Asistent/Medic`like '%Medic%' ;
  • Related