Mr.Happy Mr.Happy - 2 years ago 73
PHP Question

MySQL - How to get counts of specific value from all the records

I have course table and I am storing completion status of users with 'A'. Now I want to get how many

is available from
field for all records.

I want this result:
= 5.

Course Table:

CourseRecordIdx User CompletionStatus
--------------- ---- --------------------
1 152 A___A_______________
2 147 AA_______A__________

I have tried with
but getting count with underscore and I want to get only total of

SELECT char_length(CompletionStatus) FROM `course` where CourseRecordIdx = 36

Any idea how to get result with select query?


Answer Source

You can try with this simplest way:

 SELECT length(REPLACE("field_name","_","")) FROM `tbl_name`;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download