【发布时间】:2017-04-23 06:38:25
【问题描述】:
我不擅长编写存储过程。请帮我解决这个问题。我使用 mysql 工作台。我创建了存储过程来获得两个带有两个选择语句的输出。但它只给出了一个选择语句的输出,该语句最后写入存储过程。以下是过程。
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_procedure`(IN date_x DATE, OUT emplist3 varchar(200), OUT emplist4 varchar(200))
BEGIN
select employee.name as emplist3
from employee
where employee.id IN (
select emp_position.employee_id
from emp_position
where emp_position.employee_id NOT IN (
select emp_event.employee_id
from emp_event
where emp_event.date = date_x
)
AND emp_position.position = "Cameraman"
);
select employee.name as emplist4
from employee
where employee.id IN (
select emp_position.employee_id
from emp_position
where emp_position.employee_id NOT IN (
select emp_event.employee_id
from emp_event
where emp_event.date = date_x
)
AND emp_position.position = "Camera_Assistant"
);
END
请帮助我从上述过程中获得 emplist3 和 emplist4 的结果。 谢谢你。
【问题讨论】:
-
你应该使用内连接而不是 in 和左连接而不是 not in 以获得更好的性能,更好的 sql 查询
-
@AnkitAgrawal 我不擅长写这个数据库的东西。你能用你的解决方案编辑我的代码吗?
-
您发布的程序看起来应该可以工作。您能否编辑您的问题以包含调用它的代码(包括变量定义)、代码的实际输出以及在 mysqlworkbench 中运行时选择语句按预期工作的确认。如果您可以发布很好的示例数据,
-
您需要选择进入,检查我的答案,看看它是否有效