0

I'm looking to see if it's possible to only display results with multiple instances of a single character. For instance, if I wanted to only show rows that have the "," character in it more than 6 times.

Example: I, am, trying, to, figure, out, this, query

Would show in the results, but any row with less than 6 ","'s wouldn't show.

Mark
  • 1
  • 1
    Please tag the question with the database you are using. – Gordon Linoff May 27 '16 at 21:12
  • Possible duplicate of [Number of times a particular character appears in a string](http://stackoverflow.com/questions/9789225/number-of-times-a-particular-character-appears-in-a-string) – gemr1423 May 27 '16 at 22:07

2 Answers2

1

Here's a way using length and replace to show strings that have , 6 or more times:

select * from mytable where length(mycolumn) - length(replace(mycolumn, ",", "")) >= 6
FuzzyTree
  • 32,014
  • 3
  • 54
  • 85
0

One method uses like:

select t.*
from t
where col like '%,%,%,%,%,%,%';

This should work in any database.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786