开发者

MySQL query order by multiple items

Is it possible to order by multiple rows?

I want my users to be sorted by last_activity, but at the same time, I want the users with pictures to appear before the ones without

Something like this:

SELECT some_cols
FROM `prefix_users`
WHERE (some condi开发者_开发问答tions)
ORDER BY last_activity, pic_set DESC;


SELECT some_cols
FROM prefix_users
WHERE (some conditions)
ORDER BY pic_set DESC, last_activity;

Note that we can place ASC or DESC after each column (like above does for pic_set), or leave it to default (like above's last_activity-column).


Sort by picture and then by activity:

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜