且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

仅在 SQLite 中按字母数字字符排序

更新时间:2023-02-21 11:46:49

我会在表中添加一个额外的列,称为SortingName"或其他名称.插入时计算这个值,***不要用 SQL,而是用高级语言,在那里你有所有这些漂亮的字符串操作.

I would add an additional column in the table, called "SortingName" or something. Calculate this value when inserting, ideally not in SQL but in a higher level language where you have all these nice string operations.

我并没有真正理解这个数字.我想您能做的最简单的事情是在插入之前提取数字并将其放入另一列,例如SortingNumber".

I didn't really understand this thing with the number. I guess the simplest thing you can do is extract the number before insert and put it into another column, like "SortingNumber".

然后简单地这样排序:

Order By
  SortingName,
  SortingNumber

(或者反过来.)

另一个优势是性能.您通常会比写入数据更频繁地读取数据.您甚至可以在这两个排序列上创建索引,如果在查询中计算通常是不可能的.

Another advantage is performance. You usually read data much more often then you write it. You can even create indexes on these two sorting columns, which is usually not possible if you calculate it in the query.