Search code examples
androidsqlitesplit

Sqlite: How to split a column by delimiter and order by split count result without excluding duplicates


I'm trying to do a simple select where the returned rows are order by the result of a split count result.

Table example:

enter image description here

According to the image, If I were to split by comma and order by count result of this split, at an ascending order, it would go something like this:

T1, T2, T3

T1, T2

T1

T3

T2

I've tried this query:

Select SomeCol FROM Table GROUP BY SomeCol Order BY Count(instr(SomeCol, ',')) ASC

This works if there isn't duplicity, but it needs to work if there is duplicity. It should be able to display duplicate rows ordered by the split count.


Solution

  • Read some similar solutions and came up with one based on the ones I read.

    Select SomeCol FROM Table Order BY length( replace(SomeCol , ',', '') ) ASC