gpt4 book ai didi

Mysql case语句不起作用

转载 作者:行者123 更新时间:2023-11-29 02:14:54 25 4
gpt4 key购买 nike

我的数据库版本是5.6.34

我正在使用像这样的案例语句

SELECT 
    customerName, state, country
FROM
    customers
ORDER BY (CASE
    WHEN state IS NULL THEN country
    ELSE state
END);

表名是customers

我在 SQL 下的 mysql 数据库中编写这个查询,我还附上了我的表,你可以在那里看到,

问题是

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'state IS NULL THEN country     ELSE state END) LIMIT 0, 25' at line 6

如果有人帮助我,我将非常感激

最佳答案

只需删除那个 ()

SELECT 
customerName, state, country
FROM
customers
ORDER BY CASE
WHEN state IS NULL THEN country
ELSE state
END

关于Mysql case语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41512419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com