In Postgres/SQL, how can I get the count of a character in a column?
For example, I want to run a query which will return the number of times "X" appears in a column that has the value "XXX" - and it should return 3.
In Postgres/SQL, how can I get the count of a character in a column?
For example, I want to run a query which will return the number of times "X" appears in a column that has the value "XXX" - and it should return 3.
One method is the difference of lengths:
select (length(col) - length(replace(col, 'X', ''))) as NumX