首页 > 解决方案 > 从选择结果中执行插入查询到循环中

问题描述

我正在尝试从选择结果中执行插入查询到循环中。The problem is when I want to retrieve only one result from a select query that works correctly but when the select query retrieve more than one result that doesn't work.

GROUP_CONCAT 函数有问题吗?我该怎么做才能解决问题?

我在这里给你代码片段:

BEGIN

    SELECT idJour INTO @idJour FROM `jour` WHERE JourSemaine = DayWeek;
    
    SELECT GROUP_CONCAT(idTrancheH) AS result FROM tranchehoraire WHERE TrancheH BETWEEN heureDebut AND heureFin;
  
    loop_label : loop
    
        INSERT INTO `horaire` (`idEmployé`, `idJour`, `idTrancheH`) VALUES
        (idEmployee,@idJour, @idTrancheH);

    SET  heureDebut = ADDTIME(heureDebut ,'0:30:00.00');

        IF  heureDebut <= TIME(heureFin) THEN 
            ITERATE  loop_label;
        ELSE
                LEAVE  loop_label;
        END  IF;
        
    END LOOP;
   RETURN heureDebut;
END

非常感谢

标签: mysqlsqlloopsfor-loopphpmyadmin

解决方案


推荐阅读