php – Mysql案例语法

前端之家收集整理的这篇文章主要介绍了php – Mysql案例语法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

SELECT *
FROM case_study
ORDER BY CASE WHEN expiry_date_case > CURDATE() THEN 1 END
WHEN expiry_date_case IS NULL THEN 2 Desc END
WHEN expire_date_case < CURDATE() THEN 3 Desc END;

当我尝试运行此查询时,我收到错误

#1064 – You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use
near ‘WHEN expiry_date_case IS NULL THEN 2 Desc END WHEN
expire_date_case < CURDATE() ‘ at line 4

我在哪里做错了?

最佳答案
尝试

SELECT *
FROM case_study
ORDER BY CASE WHEN expiry_date_case > CURDATE() THEN 1 
WHEN expiry_date_case IS NULL THEN 2 
WHEN expire_date_case < CURDATE() THEN 3 END Desc

你有太多的End和太多的desc

原文链接:https://www.f2er.com/mysql/433228.html

猜你在找的MySQL相关文章