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
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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.