5.模拟生成成绩score
DELIMITER ;;
CREATE PROCEDURE insert1()
BEGIN
DECLARE a INT DEFAULT 1;
WHILE (a <= 300) DO
update airdata.airinfo set score = FLOOR( 120 + RAND() * (200)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 600) DO
update airdata.airinfo set score = FLOOR( 100 + RAND() * (200)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 900) DO
update airdata.airinfo set score = FLOOR( 140 + RAND() * (200)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1200) DO
update airdata.airinfo set score = FLOOR( 120 + RAND() * (200)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1500) DO
update airdata.airinfo set score = FLOOR( 100 + RAND() * (200)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1800) DO
update airdata.airinfo set score = FLOOR( 80 + RAND() * (200)) where id = a ;
SET a = a + 1;
END WHILE;
END;;
CALL insert1();
6.模拟生成PM2.5含量
DELIMITER ;;
CREATE PROCEDURE insert1()
BEGIN
DECLARE a INT DEFAULT 1;
WHILE (a <= 300) DO
update airdata.airinfo set PM2_5 = FLOOR( 10 + RAND() * (45)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 600) DO
update airdata.airinfo set PM2_5 = FLOOR( 50 + RAND() * (100)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 900) DO
update airdata.airinfo set PM2_5 = FLOOR( 10 + RAND() * (60)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1200) DO
update airdata.airinfo set PM2_5 = FLOOR( 60 + RAND() * (100)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1500) DO
update airdata.airinfo set PM2_5 = FLOOR( 8 + RAND() * (50)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1800) DO
update airdata.airinfo set PM2_5 = FLOOR( 50 + RAND() * (90)) where id = a ;
SET a = a + 1;
END WHILE;
END;;
CALL insert1();
7. 根据室内环境模拟生成temperature
DELIMITER ;;
CREATE PROCEDURE insert1()
BEGIN
DECLARE a INT DEFAULT 1;
DECLARE b INT DEFAULT 1;
WHILE (a <= 300) DO
IF a < 80 THEN
set b = FLOOR( 15 + RAND() * (5));
ELSEIF a <= 140 THEN
set b = FLOOR( 10 + RAND() * (10));
ELSEIF a <= 230 THEN
set b = FLOOR( 20 + RAND() * (10));
ELSE
set b = FLOOR( 10 + RAND() * (13));
END IF;
update airdata.airinfo set temperature = b where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 600) DO
IF a < 380 THEN
set b = FLOOR( 15 + RAND() * (5));
ELSEIF a <= 440 THEN
set b = FLOOR( 10 + RAND() * (10));
ELSEIF a <= 530 THEN
set b = FLOOR( 20 + RAND() * (10));
ELSE
set b = FLOOR( 10 + RAND() * (13));
END IF;
update airdata.airinfo set temperature = FLOOR( 50 + RAND() * (100)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 900) DO
IF a < 680 THEN
set b = FLOOR( 15 + RAND() * (5));
ELSEIF a <= 740 THEN
set b = FLOOR( 10 + RAND() * (10));
ELSEIF a <= 830 THEN
set b = FLOOR( 20 + RAND() * (10));
ELSE
set b = FLOOR( 10 + RAND() * (13));
END IF;
update airdata.airinfo set temperature = FLOOR( 10 + RAND() * (60)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1200) DO
IF a < 980 THEN
set b = FLOOR( 15 + RAND() * (5));
ELSEIF a <= 1040 THEN
set b = FLOOR( 10 + RAND() * (10));
ELSEIF a <= 1130 THEN
set b = FLOOR( 20 + RAND() * (10));
ELSE
set b = FLOOR( 10 + RAND() * (13));
END IF;
update airdata.airinfo set temperature = FLOOR( 60 + RAND() * (100)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1500) DO
IF a < 1280 THEN
set b = FLOOR( 15 + RAND() * (5));
ELSEIF a <= 1340 THEN
set b = FLOOR( 10 + RAND() * (10));
ELSEIF a <= 1430 THEN
set b = FLOOR( 20 + RAND() * (10));
ELSE
set b = FLOOR( 10 + RAND() * (13));
END IF;
update airdata.airinfo set temperature = FLOOR( 8 + RAND() * (50)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1800) DO
IF a < 1580 THEN
set b = FLOOR( 15 + RAND() * (5));
ELSEIF a <= 1640 THEN
set b = FLOOR( 10 + RAND() * (10));
ELSEIF a <= 1730 THEN
set b = FLOOR( 20 + RAND() * (10));
ELSE
set b = FLOOR( 10 + RAND() * (13));
END IF;
update airdata.airinfo set temperature = FLOOR( 50 + RAND() * (90)) where id = a ;
SET a = a + 1;
END WHILE;
END;;
CALL insert1();
8.模拟生成室内湿度humidity
DELIMITER ;;
CREATE PROCEDURE insert1()
BEGIN
DECLARE a INT DEFAULT 1;
WHILE (a <= 300) DO
update airdata.airinfo set humidity = FLOOR( 10 + RAND() * (20)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 600) DO
update airdata.airinfo set humidity = FLOOR( 1 + RAND() * (20)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 900) DO
update airdata.airinfo set humidity = FLOOR( 10 + RAND() * (20)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1200) DO
update airdata.airinfo set humidity = FLOOR( 1 + RAND() * (20)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1500) DO
update airdata.airinfo set humidity = FLOOR( 8 + RAND() * (20)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1800) DO
update airdata.airinfo set humidity = FLOOR( 1 + RAND() * (20)) where id = a ;
SET a = a + 1;
END WHILE;
END;;
CALL insert1();
9.根据室内空气状况模拟生成CO2含量
DELIMITER ;;
CREATE PROCEDURE insert1()
BEGIN
DECLARE a INT DEFAULT 1;
DECLARE b INT DEFAULT 1;
WHILE (a <= 300) DO
IF a < 80 THEN
set b = FLOOR( 650 + RAND() * (200));
ELSEIF a <= 140 THEN
set b = FLOOR( 650 + RAND() * (200));
ELSEIF a <= 230 THEN
set b = FLOOR( 700 + RAND() * (200));
ELSE
set b = FLOOR( 700 + RAND() * (200));
END IF;
update airdata.airinfo set CO2 = b where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 600) DO
IF a < 380 THEN
set b = FLOOR( 1000 + RAND() * (400));
ELSEIF a <= 440 THEN
set b = FLOOR( 850 + RAND() * (400));
ELSEIF a <= 530 THEN
set b = FLOOR( 800 + RAND() * (350));
ELSE
set b = FLOOR( 800 + RAND() * (400));
END IF;
update airdata.airinfo set CO2 = FLOOR( 50 + RAND() * (100)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 900) DO
IF a < 680 THEN
set b = FLOOR( 650 + RAND() * (200));
ELSEIF a <= 740 THEN
set b = FLOOR( 650 + RAND() * (200));
ELSEIF a <= 830 THEN
set b = FLOOR( 700 + RAND() * (200));
ELSE
set b = FLOOR( 700 + RAND() * (200));
END IF;
update airdata.airinfo set CO2 = FLOOR( 10 + RAND() * (60)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1200) DO
IF a < 980 THEN
set b = FLOOR( 1000 + RAND() * (400));
ELSEIF a <= 1040 THEN
set b = FLOOR( 850 + RAND() * (400));
ELSEIF a <= 1130 THEN
set b = FLOOR( 800 + RAND() * (350));
ELSE
set b = FLOOR( 800 + RAND() * (400));
END IF;
update airdata.airinfo set CO2 = FLOOR( 60 + RAND() * (100)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1500) DO
IF a < 1280 THEN
set b = FLOOR( 650 + RAND() * (200));
ELSEIF a <= 1340 THEN
set b = FLOOR( 650 + RAND() * (200));
ELSEIF a <= 1430 THEN
set b = FLOOR( 700 + RAND() * (200));
ELSE
set b = FLOOR( 700 + RAND() * (200));
END IF;
update airdata.airinfo set CO2 = FLOOR( 8 + RAND() * (50)) where id = a ;
SET a = a + 1;
END WHILE;
WHILE (a <= 1800) DO
IF a < 1580 THEN
set b = FLOOR( 1000 + RAND() * (400));
ELSEIF a <= 1640 THEN
set b = FLOOR( 850 + RAND() * (400));
ELSEIF a <= 1730 THEN
set b = FLOOR( 800 + RAND() * (350));
ELSE
set b = FLOOR( 800 + RAND() * (400));
END IF;
update airdata.airinfo set CO2 = FLOOR( 50 + RAND() * (90)) where id = a ;
SET a = a + 1;
END WHILE;
END;;
CALL insert1();