我正在學習編寫存儲過程。我想有三個select語句到我的mysql存儲過程。 第二個和第三個select語句需要其上部select語句的結果。 我試着寫如下。但沒有成功。mysql存儲過程中的多個select語句
CREATE DEFINER=`root`@`localhost` PROCEDURE `SPTeam`(IN date_x date, OUT emplist3 varchar(200))
BEGIN
SELECT
(
select emp_event.employee_id as emplist1
from emp_event
where emp_event.date = date_x
),
(
select emp_position.employee_id as emplist2
from emp_position
where FIND_IN_SET(emp_position.employee_id, emplist1)=0
AND emp_position.position = "Cameraman"
),
(
select employee.name as emplist3
from employee
where employee.id IN (emplist2)
);
END
這是我得到的錯誤。
Error Code: 1054. Unknown column 'emplist1' in 'where clause'
有人請糾正我。 謝謝U.
*但沒有成功。*表示什麼?例外? – Blank
你不能做這樣的事情,你需要在第三個IN語句中重複第二個查詢來獲得員工ID – cichy
另一件事是你不能在子查詢中獲取多行時,選擇字段 – cichy