MySQL mysql按多个项目查询顺序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4876100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:37:41  来源:igfitidea点击:

mysql query order by multiple items

mysqlsql-order-by

提问by Alexander

is is 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

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

Something like this:

像这样的东西:

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

回答by ihorko

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

回答by eumiro

Sort by picture and then by activity:

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

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

回答by Pankaj Yadav

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