Home  >  Article  >  Database  >  SQL Server 2005 数据库中的日期数据排序

SQL Server 2005 数据库中的日期数据排序

WBOY
WBOYOriginal
2016-06-07 14:55:141075browse

你的部门负责从 SQL Server 2005 数据库中的数据创建客户电子邮件地址列表。此列表必须包含上次联系每个客户的日期。 结果集中的数据必须有列名。 列表必须以上次联系客户的日期排序,最近联系的人排在前边。LastContact 列以 datetime 类型存储。日期应以MM/

你的部门负责从 SQL Server 2005 数据库中的数据创建客户电子邮件地址列表。此列表必须包含上次联系每个客户的日期。 结果集中的数据必须有列名。 列表必须以上次联系客户的日期排序,最近联系的人排在前边。LastContact 列以 datetime 类型存储。日期应以MM/DD/YYYY 的形式显示。 一位同事设计了以下查询:
SELECT email_address AS EmailAddress, CONVERT(nvarchar, lastcontact, 101) AS LastContact FROM Contact ORDER BY LastContact DESC.
你测试了此查询,并发现数据按如下顺序显示:
EmailAddress  LastContact 
andrew@contoso.com 01/24/2003 
marc@contoso.com 06/12/2005 
stefan@contoso.com 07/13/2004 
你需要修改此查询以使数据按正确的顺序排列。 你想要对性能不造成任何负面影响而达成此目标,该怎样做?
SELECT email_address AS EmailAddress, CONVERT(nvarchar, lastcontact, 101) AS Last_Contact FROM Contact ORDER BY lastcontact DESC
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn