ARAVINDH GOPI - 1 year ago 76

MySQL Question

I have a table like the one in the picture, I want to select all '6' in m1,m2,m3,m4.m5 field where name is equal to sivakumar.

I have tried

`Select m1,m2,m3,m4,m5 from table where m1=6 and m2=6 and so on... where staff_name=sivakumar`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

Sorry for the inconvienience, my question is "how to count field values of multiple rows". I got my answer below

```
select (sum(case when m1 = 6 then 1 else 0 end) +
sum(case when m2 = 6 then 1 else 0 end) +
sum(case when m3 = 6 then 1 else 0 end) +
sum(case when m4 = 6 then 1 else 0 end) +
sum(case when m5 = 6 then 1 else 0 end)) as abc from table where staff_name='sivakumar';
```