php - Row Count using one SQL String

Solution:
You can combineSUM()
andIF()
functions to count all 'No' in selected rows like this.
SELECT
SUM(IF(incident.ppe = 'No', 1, 0)),
SUM(IF(incident.induction = 'No', 1, 0)),
SUM(IF(incident.actions = 'No', 1, 0)),
SUM(IF(incident.ssops = 'No', 1, 0))
FROM incident
TheIF()
function will assign value 1 to the rows where the condition is true (where the attribute value is equal to 'No') and 0 to other rows.SUM()
will then count a total of all rows. So if there are 5 'No' in ppe from a total of 9 rows theSUM()
result will be 1+1+1+1+1+0+0+0+0=5
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to undefined function str_contains()
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.