natural-sort

Using MySQL sort varchar column numerically with cast as unsigned when the column can begin or end with letters

 ̄綄美尐妖づ 提交于 2019-12-01 08:28:33
问题 I've ran into something I'm not really sure how to handle here. I'm building a database to store information on sports cards, and I'm having a bit of an issue with some sorting when I want to see certain cards. For background, each card (row in the database) has information on year, set the card is from, player on the card, and card number (there's more info than that, but this is all that's relevant here). When I see results, I want things to be sorted by year, then set, then player, then

Natural sort on Django Queryset

≡放荡痞女 提交于 2019-12-01 04:57:50
I am working on a system that lists out a range of products sorted by their product code. The product codes are made up of two letters for the followed by a number, for example EG1. I currently sort these products by doing a simple Product.objects.order_by('product_code') , however as there can be multiple digit product codes (for example EG12), these will come out above ahead of the single digit codes. i.e EG1, EG11, EG12, EG13 ... EG19, EG2, EG20 etc I know that adding leading zeros to the product codes will fix this (i.e EG01 rather than EG1) but as there is already printed literature and

Natural sort on Django Queryset

﹥>﹥吖頭↗ 提交于 2019-12-01 01:58:51
问题 I am working on a system that lists out a range of products sorted by their product code. The product codes are made up of two letters for the followed by a number, for example EG1. I currently sort these products by doing a simple Product.objects.order_by('product_code') , however as there can be multiple digit product codes (for example EG12), these will come out above ahead of the single digit codes. i.e EG1, EG11, EG12, EG13 ... EG19, EG2, EG20 etc I know that adding leading zeros to the

Alphanumeric Sort

谁说我不能喝 提交于 2019-12-01 01:24:33
I need quick help in sorting data at SQL side. I am using Sqlserver 2012 (good if answer give with the new feature). I already search some links as Sorting in alphanumeric , Alphanumeric string Sorting in Sqlserver - Code project . But does not give the desired result. Still What I have try : CREATE TABLE dbo.Section ( Section varchar(50) NULL ) INSERT INTO dbo.Section (Section.Section) VALUES ('Campsit no.43') INSERT INTO dbo.Section (Section.Section) VALUES ('Campsit no.41') INSERT INTO dbo.Section (Section.Section) VALUES ('Campsite No. 11') INSERT INTO dbo.Section (Section.Section) VALUES

Alphanumeric Sort

限于喜欢 提交于 2019-11-30 21:38:53
问题 I need quick help in sorting data at SQL side. I am using Sqlserver 2012 (good if answer give with the new feature). I already search some links as Sorting in alphanumeric , Alphanumeric string Sorting in Sqlserver - Code project. But does not give the desired result. Still What I have try : CREATE TABLE dbo.Section ( Section varchar(50) NULL ) INSERT INTO dbo.Section (Section.Section) VALUES ('Campsit no.43') INSERT INTO dbo.Section (Section.Section) VALUES ('Campsit no.41') INSERT INTO dbo

How can I sort a list of strings by numbers in them?

懵懂的女人 提交于 2019-11-30 14:52:25
问题 An easy one no doubt for you... I have a list of filenames which are like so; fw_d.log.1.gz through fw_d.log.300.gz When i use this below code block, it almost sorts it the way i want, but not quite. #!/usr/bin/perl -w my $basedir = "/var/log"; my @verdir = qw(fw_d); my $fulldir; my $configs; my $combidir; foreach $combidir (@verdir) { $fulldir = "$basedir/$combidir"; opendir (DIR, $fulldir); my @files = grep { $_ ne '.' && $_ ne '..' && $_ ne 'CVS' readdir DIR; closedir (DIR); @files1 = sort

Natural sort with SQL Server

删除回忆录丶 提交于 2019-11-29 16:39:43
I want to convert the order of the values with column name PTNT_VST_CSNO from the following : VMIP1 VMIP10 VMIP11 VMIP2 VMIP20 VMIP21 VMIP3 VMIP31 VMIP32 VMIP5 VMIP6 VMIP7 VMIP8 VMIP9 VMOP10 VMOP11 VMOP12 VMOP3 VMOP30 VMOP31 VMOP32 VMOP4 VMOP40 VMOP41 VMOP42 VMOP43 VMOP7 VMOP70 VMOP71 VMOP8 VMOP9 to: VMIP1 VMIP2 VMIP3 VMIP5 VMIP6 VMIP7 VMIP8 VMIP9 VMIP10 VMIP11 VMIP20 VMIP21 VMIP31 VMIP32 VMOP3 VMOP4 VMOP7 VMOP8 VMOP9 VMOP10 VMOP11 VMOP12 VMOP30 VMOP31 VMOP32 VMOP40 VMOP41 VMOP42 VMOP43 VMOP70 VMOP71 I want to sort the numeric part of 'vmip' first then that of 'vmop'.. I tried a lot but failed

Sort string as number in sql server

混江龙づ霸主 提交于 2019-11-29 13:31:25
I have a column that contains data like this. dashes indicate multi copies of the same invoice and these have to be sorted in ascending order 790711 790109-1 790109-11 790109-2 i have to sort it in increasing order by this number but since this is a varchar field it sorts in alphabetical order like this 790109-1 790109-11 790109-2 790711 in order to fix this i tried replacing the -(dash) with empty and then casting it as a number and then sorting on that select cast(replace(invoiceid,'-','') as decimal) as invoiceSort...............order by invoiceSort asc while this is better and sorts like

How to do sorting on irregular Alphanumeric data in postgres sql

人盡茶涼 提交于 2019-11-29 12:09:50
I have the following sample data for a particular column symbol for sample table. (Update:) The data is not in a regular pattern. Number may occur at any place in between characters. symbol COL4A1 COL4A3 COL8A2 COL2A1 COL12A1 COL12A1 COL16A1 COL19A1 I need to sort the this data on database level. I used the following query: select symbol from sample order by symbol asc Result is follows: COL12A1 COL12A1 COL16A1 COL19A1 COL2A1 COL4A1 COL4A3 COL8A2 But I need to get the order in the following way: COL2A1 COL4A1 COL4A3 COL8A2 COL12A1 COL12A1 COL16A1 COL19A1 PostgreSQL doesn't offer a number-aware

Java String Number Comparator

二次信任 提交于 2019-11-29 04:22:31
I have a method returning a list of String that need to be sorted. However, I'm running into the old String number sorting issue and was wondering if any one could assist with a Comparator implementation or point me in the direction of one. The list is going to return something list this: State Lower Legislative District 1 State Lower Legislative District 11 State Lower Legislative District 12 ... State Lower Legislative District 2 ... State Lower Legislative District 100 ... State Upper Legislative District 1 State Upper Legislative District 11 ... So, first I need to do a basic String sort,