我想对我的用户列表进行双重排序。这可能在一个MySQL查询中吗?
activity
ID
例如:
1 Jack Active
2 Jill Active
5 Jens Active
3 Harry Inactive
4 Larry Inactive
6 Luke Inactive
答案 0 :(得分:8)
您可以使用ORDER BY
子句根据需要对列进行排序。
SELECT id, name, activity
FROM userList
ORDER BY Activity, ID
我建议阅读MySQL ORDER BY
文档。您可以按ASC
或DESC
顺序对数据进行排序:MySQL: ORDER BY Optimization
答案 1 :(得分:4)
SELECT id, name, activity
FROM your_table
ORDER BY activity ASC, id ASC
答案 2 :(得分:1)
Select * from table order by activity, ID;
答案 3 :(得分:1)
SELECT *
FROM table_name
ORDER BY activity, ID;
答案 4 :(得分:0)
是,
SELECT (user.name|| ' ' || user.status) AS sorted_list
FROM STUDENTS
ORDER BY user.status, user.name