多级排序
我有一个表,其中包含一些记录,其中包含名称、评级等字段。
我首先想根据评级将结果限制为 20 进行排序,然后在此结果集上希望进一步应用基于名称的排序。
我知道要排序我们需要使用类似的查询,
Select * from table order by rating Desc limit 20
但是在此结果集上如何应用另一个级别的排序?如何将这两种排序合并到一个 sqlite 语句中?
I have a table with some records with fields like name, rating etc.
I first want to sort based on rating limiting results to 20 and then on this resultset want to further apply sort based on name.
I know to sort we need to use the query like
Select * from table order by rating Desc limit 20
but on this resultset how to apply another level of ordering? How can I combine these two sorts in one sqlite statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用例如
ORDER BY rating DESC, name ASC
按评级排序,然后,如果评级相等,则按名称排序。You could use e.g.
ORDER BY rating DESC, name ASC
to sort by rating and then, if the ratings are equal, by name.这个查询应该可以解决问题:
This query should do the trick: