MySQL Query to get a list of events with at least 3 different status? -


i have database containing 2 tables :

events (id, name, is_active)

event_logs (id, event_id, status, message)

i'd list events had @ least 3 different status logs in , still active (is_active=1) , can't come correct mysql query that.

(i can add more details if needed, ask :) ).

here's sqlfiddle : http://sqlfiddle.com/#!9/a7442

in example, i'm looking event id 2 because contains 3 different status in event_log : info, warning , error. event id 1 , 3 contains less 3 , excluded.

thank help!

maybe more coffee required...

select e.*   events e   join event_logs l     on l.event_id = e.id  is_active=1   group      e.id having count(distinct l.status) >=3 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -