我正在尝试使用存储过程查找具有特定薪资范围的员工人数,我得到的结果与简单查询(下面的第二个查询)的结果不相等,这意味着存储过程工作不正常?
我希望有人能帮我。
--答:空/没有工资金额低于38000,但是按照商店程序我得到967330
第二,在store过程中有没有其他方法来缩短case语句?在当前版本中,每次都必须添加子查询。
数据库名称:employees列名:salary employee\u id=emp\u no
DELIMITER $$
CREATE PROCEDURE SALARY_RANGE
(INOUT no_employees INT, IN salary INT)
BEGIN
CASE
WHEN (salary <= 38000) THEN (SELECT COUNT(emp_no) INTO no_employees
FROM salaries
WHERE salary <= 38000);
WHEN (salary<= 68000) THEN (SELECT COUNT(emp_no) INTO no_employees
FROM salaries
WHERE salary <= 68000);
WHEN (salary <= 88000) THEN (SELECT COUNT(emp_no) INTO no_employees
FROM salaries
WHERE salary <= 88000);
WHEN (salary <= 100000) THEN (SELECT COUNT(emp_no) INTO no_employees
FROM salaries
WHERE salary <= 100000);
ELSE (SELECT COUNT(emp_no) INTO no_employees
FROM salaries WHERE salary > 100000);
END CASE;
END$$
CALL SALARY_RANGE(@finding_salary_range_count,'38000')$$
select @finding_salary_range_count;
-- to check the if the answer matched the above store procedure
select count(case when salary <= 88000 then emp_no else null end) as count_sal
from salaries;
1条答案
按热度按时间ovfsdjhp1#
我希望这样的代码:
我不认为需要多个
SELECT
声明。