So will ich es Fehler, hier produziert jedoch dynamischen Wert von Param gespeicherte Prozedur aus übergeordneter Abfrage zu übergeben ist die Abfrage:MySQL: Stored Procedure in WHERE-Klausel
SELECT *
FROM mytable
WHERE mytable.user_id IN (CALL getDownlines(mytable.user_id))
Allerdings, wenn ich direkt laufen SP, es funktioniert gut:
CALL getDownlines(100)
Irgendwelche Ideen bitte?
Hier SP als Referenz, nicht sicher, wie es in Funktion zu konvertieren:
DELIMITER $
DROP PROCEDURE IF EXISTS getDownlines$
CREATE PROCEDURE getDownlines(in_id INT)
BEGIN
drop table if exists temp1;
drop table if exists temp2;
drop table if exists results;
create temporary table temp2 as (select id, upline_id from agents where upline_id = in_id);
create temporary table results as (select id, upline_id from temp2);
create temporary table temp1 (id int, upline_id int);
while (select count(*) from temp2) do
insert into temp1 (id, upline_id)
select a.id, upline_id
from agents a
where a.upline_id in (select id from temp2) ;
insert into results (id, upline_id)
select distinct id, upline_id
from temp1;
delete from temp2;
insert into temp2 (id, upline_id)
select distinct id, upline_id
from temp1;
delete from temp1;
end while;
select a.*
from results r
join agents a
on a.id = r.id;
drop table if exists temp1;
drop table if exists temp2;
drop table if exists results;
End $$
DELIMITER ;
machen Sie es zu einer Funktion, und Sie können es anrufen –