简体   繁体   English

按姓氏和名字排序

[英]Sort by last name and first name

I have a small little problem. 我有一个小问题。 I am have a drop down list that displays all of our customers names. 我有一个下拉列表,其中显示了我们所有的客户名称。 As of right now, the list is sorted by last name (AZ). 截至目前,该列表按姓氏(AZ)排序。 But for example, there are 250 people with the last name "Smith". 但是例如,有250个人的姓氏为“ Smith”。 What I need is a way that the last name of each customer to stay the way it is but I need the first names to be listed alphabetically as well. 我需要的是使每个客户的姓氏保持原样的方式,但是我也需要按字母顺序列出名字。 Here is an example: 这是一个例子:

Customer #1 - Smith, Jean
Customer #2 - Smith, Allen
Customer #3 - Smith, Davey

What I would like is this: 我想要的是这样的:

Customer #1 - Smith, Allen
Customer #2 - Smith, Davey
Customer #3 - Smith, Jean

Here is how I am pulling the list now: 这是我现在提取列表的方式:

SELECT customer_id, first_name, last_name FROM customers ORDER BY last_name

只需将您的ORDER BY子句更改为:

ORDER BY last_name, first_name

调整您的SQL语句,添加带有适当字段名称的ORDER BY子句:

ORDER BY last_name ASC, first_name ASC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM