mysql - 无法使用 case 且存在于 sql 语句中

标签 mysql sql

我正在尝试:

select
case when exists (id) then id else 'n/a' end as id
from mytable
where id="35";

但是我弹出了一些错误或其他错误。我做错了什么,还是这根本不可行?

check the manual that corresponds to your MySQL server version for the right syntax to use near 'id) then id else 'n/a' end as id from mytable where id="35"' at line 2 */

最佳答案

select case when id = 35 then id else 'n/a' end as id
from mytable
order by case when id = 35 then 1 else 2 end 
limit 1

SQLFiddle demo

关于mysql - 无法使用 case 且存在于 sql 语句中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19007995/

相关文章:

java - JOOQ:从一个表中选择另一个表中不存在的键

mysql - 如果值出现在表中的其他位置,请选择该值

php - 从多个上传的图像中获取单个图像

mysql - 如何将 1 个表连接到产品和类别应用程序树中(2 个不同的表作为一个表)?

php - 由于 Group By 语句,mysql 查询出现奇怪的情况

sql - 获取范围之间的值

sql - 每月计算新客户

sql - 不像条件太慢的地方

php - Yii2:无法通过 + 1 更新列值

SQL 性能 : UNION or ORDER BY