There is a table event :

 (id_user) (status) 1 active 2 load 3 active 1 load 2 active 3 active 1 active 3 fail 

For each id_user you must output the number of lines of this id_user , passing by the condition (status="active" OR status="load") AND (status!="fail") . The result is something like this:

 (id_user) count(status) 1 3 2 2 

id_user = 3 did not hit, because it had one line status!="fail" .

If such a request is possible, a second question is possible immediately, if you need to exclude those id_user that have more than two lines of status!="fail" ?

  • What kind of SQL do you have? Just now, MySQL came across ru.stackoverflow.com/questions/688427 with the same count with the conditions your tasks should also be solved ... - Mike
  • SQL β€Œβ€Œβ€β€ β€Œβ€Œβ€β€ β€Œβ€Œβ€β€ 17 β€Œβ€Œβ€β€ β€Œβ€Œβ€β€ β€Œβ€Œβ€β€ β€Œβ€Œβ€β€ β€Œβ€Œβ€β€ β€Œβ€Œβ€β€ SQL MySQL - Grafov
  • do so by analogy with that answer, sum(status="active" OR status="load") and in having check sum(status="fail") to 0 or not more than 2 - Mike
  • For the case of AND (status!="fail") , since there are only 3 statuses, and one of them must be absent, the quantity can be considered the usual COUNT (). - Akina

0