创建存储过程生成模拟数据2——搭建数据分析平台

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();



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值