【问题标题】:Why is the new row not being renamed in MySQL? [closed]为什么新行没有在 MySQL 中重命名? [关闭]
【发布时间】: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


【解决方案1】:

“AS 状态”应该在括号之外。你不需要原来的括号

【讨论】:

  • 我们通常只是对 TYPO 发表评论然后删除问题,因为拼写错误对其他人没有任何实际用途
【解决方案2】:

尝试删除括号并运行

SELECT *, 
CASE
    WHEN CourseCode = 907 THEN 'Already in the course'
    WHEN CourseCode <> 907 THEN 'Upgraded to the course'
    Else NULL
END AS Status
FROM ecestudents;

【讨论】:

  • 我们通常只是对 TYPO 发表评论然后删除问题,因为拼写错误对其他人没有任何实际用途
猜你喜欢
  • 2014-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-28
  • 2011-05-30
相关资源
最近更新 更多