【发布时间】:2021-09-13 19:19:45
【问题描述】:
这是我的代码
SELECT *,
-- Add the status of the student depending on the CourseCode
(CASE
WHEN CourseCode = 907 THEN 'Already in the course'
WHEN CourseCode <> 907 THEN 'Upgraded to the course'
Else NULL
END AS Status)
FROM ecestudents;
不幸的是,由于某种原因,它抛出了一个错误。但如果我删除 AS Status 它运行正常,但我想重命名我正在使用 case 语句创建的新行。
【问题讨论】:
-
将
END AS Status)更改为END) AS Status -
这不是“重命名行”,而是“别名列”
-
正确,因为 SQL 中的行没有名称。 (列有名称)
-
这是
case表达式,而不是语句。
标签: mysql sql case mysql-workbench