Nieznana kolumna mysql i losowanie stringa.

0

Witam posiadam dwie tabele pracownicy i ludzie. W tabeli ludzie posiadam wiele peselów, które muszę randomowo dodać do tabeli pracownicy przy czym osoby muszą być pełnoletnie. Nie patrzę już na miesiące bo ma być to tylko prowizoryczne. Nie wiem dlaczego nie widzi mi kolumny ludzie.pesel choć wszystko wydaje mi się super logiczne. Pozdrawiam

DELIMITER $$
CREATE PROCEDURE proc_pelnoletni()
BEGIN
    DECLARE s INT DEFAULT 0;
    etykieta3:LOOP
	UPDATE pracownicy 
	  SET pracownicy.pesel = (Select aa from(Select pesel as aa from ludzie where left(ludzie.pesel,1)<=9 and left(ludzie.pesel,2)<=9 order by rand() Limit 1) as A);
      SET s = s+1;
      IF s>=175 
      THEN LEAVE etykieta3; 
      END IF ;
      END LOOP;
      END $$
DELIMITER $$
call proc_pelnoletni();
0
select * from peoples;
+----+-------------+
| id | pesel       |
+----+-------------+
|  1 | 18395858492 |
|  2 | 18395123492 |
|  3 | 15855648391 |
|  4 | 29123459857 |
|  5 | 19123229857 |
+----+-------------+
delimiter //

create function sum1(number_as_str char(11), quantity int)
returns int deterministic
begin

declare i int default 1;
declare collect int default 0;

while i <= quantity do
	
	set collect = collect + cast(substring(number_as_str,i,1) as unsigned);
	
	set i = i + 1;
end while;

return collect;

end;//
select x, z, id, pesel from (select cast(sum1(left(peoples.pesel,2), 2) as unsigned) as x, cast(left(peoples.pesel,1) as unsigned) as z, id, pesel from peoples) as y where x<=9 and z<=9;
+------+------+----+-------------+
| x    | z    | id | pesel       |
+------+------+----+-------------+
|    9 |    1 |  1 | 18395858492 |
|    9 |    1 |  2 | 18395123492 |
|    6 |    1 |  3 | 15855648391 |
+------+------+----+-------------+

delimiter //
create procedure proc_adult()
begin
	declare s int default 0;
	label3: LOOP
		update trees3 
		set trees3.kind = (SELECT pesel FROM (SELECT CAST(sum1(LEFT(peoples.pesel,2), 2) AS UNSIGNED) AS x, CAST(LEFT(peoples.pesel,1) AS UNSIGNED) AS z, pesel FROM peoples)
		AS y WHERE x<=9 AND z<=9 order by rand() limit 1);
		
		if s > (select count(*) from trees3) then 
			leave label3;
		end if;
		set s = s + 1;
	end loop;
end//

delimiter ;

call proc_adult();

0

Tylko nie napisałem, że moim primary key jest pesel a nie id. Pozdrawiam

1 użytkowników online, w tym zalogowanych: 0, gości: 1