I have a table holding strings with multiple "." sections.
eg,
"field1.field2.field3"
"field1.field2.field4"
"field1.field2.field5"
"field1.field2.field6"
"field40.field50.field60"
I would to query the table and return a distinct list of items up until the last ".".
In the above example the query should return
"field1.field2"
"field40.field50"
I am aware of SELECT DISTINCT
, INSTR
and SUBSTR
but how do I combine all in the same query?
SQLite has very poor string functionality. One method that almost gets you there is:
select rtrim(col, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234456789')
You can then get what you want by doing:
select substr(col, 1, length(rtrim(lower(col), 'abcdefghijklmnopqrstuvwxyz01234456789')) - 1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.