Ankit Sharma
Ankit Sharma

Reputation: 4071

how to count no of specific symbol in a row in mysql

I have a table with a row with the data like '/2323/3235/4545/222/' how can i count the number of / in every row using mysql only.

Upvotes: 5

Views: 142

Answers (2)

M.I.T.
M.I.T.

Reputation: 1042

link

SELECT LENGTH('/2323/3235/4545/222/') - LENGTH(REPLACE('/2323/3235/4545/222/', '/', '')) AS `occurrences`

Upvotes: 3

JK.
JK.

Reputation: 5136

A quick search came up with this:

SELECT LENGTH('/2323/3235/4545/222/') - LENGTH(REPLACE('/2323/3235/4545/222/','/','')) ... etc;

Upvotes: 5

Related Questions