sql - SQLite Order Rows by Last Characters in a String -


i'm using sqlite database java application , have single varchar column bunch user stats written, read, , parsed java program. want have query can sort rows last stat in column. stats separated commas , lengths vary need can take whole last section of text (which text last comma end of data) , order that. easy within java application more resource intensive why directly query. in practice actual column data looks this:

2015/7/4 17:24:38,[(data1, 1, 1436394735787)|(data2, 4, 1436394739288)], 5 

and i'm trying order rows based on last 5 or whatever else might (it can multiple digits too). iv'e tried find on internet lot of issues if had because of syntax errors (even when copied query exactly) or problems specific function doesn't exist , i'm not sure cause of errors is. i'm not familiar mysql simple answer appreciated.

as quick , hacky solution (low performance if have huge amount of data):

select * [tbl] order cast(substr([col], instr([col], '],') + 2) integer); 

but hayley suggested, re-evaluate data, can use:

insert [new-tbl] select substr(val, 0, c1),        substr(val, c1+1, c2-c1),        cast(substr(val, c2+2) integer),        [more-cols] (     select instr([col], ',') c1,            instr([col], '],') c2,            [col] val,            [more-cols]     [tbl]); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -