I have a table in the form:
test_name | test_result
-----------------------
test1 | pass
test2 | fail
test1 | pass
test1 | pass
test2 | pass
test1 | pass
test3 | pass
test3 | fail
test3 | pass
As you can see all test1’s pass while test2’s and test3’s have both passes and fails.
Is there a SQL statement that I can use to return the distinct names of the tests that only pass? E.g. test1
You can group by the test_name, count the number of passes, and check if it is the same as the number of rows in the group.
Alternatively, count the number of fails and check that it is zero:
Result:
Test data: