1

Wanted to ask if anyone can help me with (code or commands to use) an sql query to count how many times the question mark character appears in table *exp_comments*, field comment?

Thanks! Lee

0

1 Answer 1

3

To get a total of all occurrences across all comments:

SELECT SUM(LENGTH(comment) - LENGTH(REPLACE(comment, '?', ''))) AS occurrences FROM exp_comments

To get the count for each comment in a query result:

SELECT LENGTH(comment) - LENGTH(REPLACE(comment, '?', '')) AS occurrences FROM exp_comments

(MySQL doesn't have a specific function for this, but I found this clever technique - which takes the field's character count and subtracts its count with all of your target character removed - here.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.