如何对包含序数的文本进行排序?
我正在开发一个应用程序,会员可以在其中选择 DVD 并将其添加到他们的“愿望清单”中。可以打印包含当前愿望清单的报告。如果 DVD 标题包含序数(第一、第二、第三、第四等),我的客户希望按数字(1、2、3、4 等)排序。
例如,如果此脚本用于创建、填充和查询表:
CREATE TABLE Dvd (
TitleID INT IDENTITY PRIMARY KEY
,Title VARCHAR(256)
)
GO
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete First Season')
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Second Season')
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Third Season')
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Fourth Season')
SELECT Title FROM Dvd ORDER BY Title
该查询将返回以下结果:
M*A*S*H - The Complete First Season M*A*S*H - The Complete Fourth Season M*A*S*H - The Complete Second Season M*A*S*H - The Complete Third Season
是否有人对对标题进行排序的有效方法有任何建议,以便根据以下顺序列出标题:与序数文本关联的实际数字:
M*A*S*H - The Complete First Season M*A*S*H - The Complete Second Season M*A*S*H - The Complete Third Season M*A*S*H - The Complete Fourth Season
I am working on an application where members can select a DVD and add it to their "wish list". A report can be printed with the current wish list. If the DVD title contains an ordinal number (first, second, third, fourth, etc), my customer would like to sort by the number (1, 2, 3, 4, etc).
For example, if this script is used to create, populate, and query a table:
CREATE TABLE Dvd (
TitleID INT IDENTITY PRIMARY KEY
,Title VARCHAR(256)
)
GO
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete First Season')
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Second Season')
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Third Season')
INSERT INTO Dvd (Title) VALUES ('M*A*S*H - The Complete Fourth Season')
SELECT Title FROM Dvd ORDER BY Title
The query returns the following results:
M*A*S*H - The Complete First Season M*A*S*H - The Complete Fourth Season M*A*S*H - The Complete Second Season M*A*S*H - The Complete Third Season
Does anybody have any suggestions for an efficient way to sort the titles so they would be listed in this order, based on the actual number associated with the ordinal number text:
M*A*S*H - The Complete First Season M*A*S*H - The Complete Second Season M*A*S*H - The Complete Third Season M*A*S*H - The Complete Fourth Season
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设TitleID按顺序递增,就按TitleID排序即可。
Assuming the TitleID's increase in order, just order by TitleID.