按个案和名称排序

时间:2017-05-29 07:53:14

标签: php sql

我有一个sql语句,它将external作为最后一个,但我也希望按名称对结果的其余部分进行排序。是否可以使用两个ORDER BY

SELECT `id`
FROM `user`
WHERE `parent` = %d AND `isFolder` = 1
ORDER BY CASE WHEN name = \'External\' THEN 2 ELSE 1 END

1 个答案:

答案 0 :(得分:0)

根据要求,我的评论作为答案!

只需将name列添加到ORDER BY列表中:

SELECT `id`
FROM `user`
WHERE `parent` = %d AND `isFolder` = 1
ORDER BY CASE WHEN name = \'External\' THEN 2 ELSE 1 END, name