按多个项目排列的 MySQL 查询顺序

可以按多行排序吗?

我希望我的用户按 last_activity排序,但同时,我希望有图片的用户出现在没有图片的用户之前

Something like this:

SELECT some_cols
FROM `prefix_users`
WHERE (some conditions)
ORDER BY last_activity, pic_set DESC;
175164 次浏览
SELECT some_cols
FROM prefix_users
WHERE (some conditions)
ORDER BY pic_set DESC, last_activity;

注意 ,我们可以在每个列后面放置 ASCDESC(就像上面对 pic_set所做的那样) ,或者将其保留为默认值(就像上面的 last_activity-column)。

按照图片和活动排序:

SELECT some_cols
FROM `prefix_users`
WHERE (some conditions)
ORDER BY pic_set, last_activity DESC;
SELECT id, user_id, video_name
FROM sa_created_videos
ORDER BY LENGTH(id) ASC, LENGTH(user_id) DESC