mysql query order by multiple items

走远了吗. 提交于 2019-11-26 12:09:46

问题


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

Something like this:

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

回答1:


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



回答2:


Sort by picture and then by activity:

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



回答3:


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


来源:https://stackoverflow.com/questions/4876100/mysql-query-order-by-multiple-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!