[英]Need help with MySQL query
Is it possible to edit the query below: 是否可以在下面编辑查询:
SELECT *
FROM t1
ORDER BY CASE
WHEN projects_status = 'active' THEN 1
WHEN projects_status = 'expired' THEN 2
WHEN projects_status = 'closed' THEN 3
END
to have results in the following sorting order: 具有以下排序顺序的结果:
A comparison will return a 0 or 1, where a 0 is normally sorted before a 1. So when you say ASC, you probably want it the return the rows where this is true (1) on top. 比较将返回0或1,其中0通常在1之前排序。因此,当您说ASC时,您可能希望它返回上面为true的行(1)。 So you need to use DESC in this case.
因此,在这种情况下,您需要使用DESC。
ORDER BY
projects_status = 'active' DESC,
projects_status = 'expired' ASC,
projects_status = 'closed' ASC
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.