如何对项目进行排序,然后使用 SQL 按另一个条件再次排序 [英] How to sort the items then sort again by another condition using SQL

查看:39
本文介绍了如何对项目进行排序,然后使用 SQL 按另一个条件再次排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MySQL,我想对记录进行排序,或者我想对记录进行分组,然后按另一种条件再次对其进行排序,例如我有 6 个项目,

I'm using MySQL, and I want to sort a record or I want to group a record then sort it again by another condition like for example I have 6 items,

Names Group
Jack  G1
Dian  G2
Emily G2
Dean  G1
Teddy G2
Gabe  G1

所以我想按字母顺序或按名称按组对它进行排序.喜欢,

So I want to sort this by group in alphabetized orby by name. Like,

Dean  G1
Gabe  G1
Jack  G1
Dian  G2
Emily G2
Teddy G2

所以我的问题是,如何在 MySQL 中进行这样的排序?

So my problem is, how can I sort like this in MySQL?

谢谢.

推荐答案

所以您想先按一列排序,然后再按另一列排序?您可以在查询的 ORDER BY 子句中指定多个列 - 用逗号分隔它们,第一个将是主要"排序,然后列表中的后续列将在

So you want to order by one column first and then another? You can specify more than one column in the ORDER BY clause of a query - separate them by commas, and the first one will be the 'major' sort, then subsequent columns in the list will be sorted within that.

这篇关于如何对项目进行排序,然后使用 SQL 按另一个条件再次排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆