mysql查询顺序由多个项目组成

时间:2011-02-02 15:12:56

标签: mysql sql-order-by

可以按多行排序吗?

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

的用户之前

这样的事情:

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

3 个答案:

答案 0 :(得分:130)

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

答案 1 :(得分:13)

按照图片排序,然后按活动排序:

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

答案 2 :(得分:0)

SELECT id, user_id, video_name
FROM sa_created_videos
ORDER BY LENGTH(id) ASC, LENGTH(user_id) DESC