1
You did not specify which database you are using, but you can do this in several ways. I used the example Mysql and made 2 ways to do this:
Using EXISTS:
select distinct
m.registro
from movimento m
where
exists (select 1 from movimento x where x.registro = m.registro and x.evento = 'e1')
and
exists (select 1 from movimento x where x.registro = m.registro and x.evento = 'e2')
and
exists (select 1 from movimento x where x.registro = m.registro and x.evento = 'e3');
Upshot:
registro
001
003
Using URGE and GROUP_CONCAT:
select distinct
m.registro,
GROUP_CONCAT(m.evento) as eventos
from movimento m
group by m.registro
having
INSTR(GROUP_CONCAT(m.evento),'e1') > 0
and
INSTR(GROUP_CONCAT(m.evento),'e2') > 0
and
INSTR(GROUP_CONCAT(m.evento),'e3') > 0;
Upshot:
registro eventos
001 e1,e2,e3
003 e1,e2,e3
I put in the Sqlfiddle
Use the WHERE clause. A short tutorial: https://www.w3schools.com/sql/sql_where.asp
– Netinho Santos
I understand, but in case it would have to show the workers who own exactly the three events only
– Naaliel Corrêa