如何对包含序数的文本进行排序?

发布于 2024-11-05 07:44:28 字数 979 浏览 0 评论 0原文

我正在开发一个应用程序,会员可以在其中选择 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转身以后 2024-11-12 07:44:28

假设TitleID按顺序递增,就按TitleID排序即可。

Assuming the TitleID's increase in order, just order by TitleID.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文