我在第一个“;”之后不断收到1064语法错误在第一次发表声明时。我试过here和here无效的提示。帮助任何人?
DELIMITER //
CREATE PROCEDURE `test` ()
BEGIN
SELECT *,
case
when variable_1 between 0.75 and 4 then 4;
when variable_1 between 0 and 0.74 then "<4";
when variable_1 between 4.1 and 365 then ">4";
end case as variable_2;
END //
答案后的修正问题:
实际代码:
DELIMITER //
CREATE PROCEDURE `infant_outcomes`.`new_procedure` ()
BEGIN
SELECT * FROM CDI
INNER JOIN
-- CDI subquery grouping and filtering
(SELECT CDI.subj_CDI as subj_CDI_grouping, Min(hearing_age_CDI) min_hearing_age_CDI,
case
when CDI.hearing_age_CDI between 1.75 and 4.25 then 3
when CDI.hearing_age_CDI between 4.75 and 7.25 then 6
end as hearing_age_CDI_group
FROM CDI
group by CDI.subj_CDI, hearing_age_CDI_group
ORDER BY CDI.subj_CDI, CDI.hearing_age_CDI ASC) CDI_filtered
on
CDI.subj_CDI = subj_CDI_grouping
AND CDI.hearing_age_CDI = CDI_filtered.min_hearing_age_CDI
where hearing_age_CDI_group is not null
ORDER BY
CDI.subj_CDI, CDI_filtered.hearing_age_CDI_group
END //
我在“结束//”时收到语法错误虽然以下两个答案的组合有效,但实际代码本身会抛出错误...
答案 0 :(得分:2)
因为你破坏了陈述。
SELECT *,
case
when variable_1 between 0.75 and 4 then "4"
when variable_1 between 0 and 0.74 then "<4"
when variable_1 between 4.1 and 365 then ">4"
end as variable_2;
你错过了分号
ORDER BY
CDI.subj_CDI, CDI_filtered.hearing_age_CDI_group;
^________ this.
答案 1 :(得分:1)
案例表达式以“结束”结束,而非“结束案例”。
删除尾随的“案例”:
DELIMITER //
CREATE PROCEDURE `test` ()
BEGIN
SELECT *,
case
when variable_1 between 0.75 and 4 then 4;
when variable_1 between 0 and 0.74 then "<4";
when variable_1 between 4.1 and 365 then ">4";
end as variable_2; -- "case" removed
END //