Published in : 2022-03-04
Give the following table:
I need to extract users who are in group 1 and 2, which means I only need to retrieve user 123. My query goes like the following:
with two_groups as ( select employee_id from table1 where group in ('group1', 'group2') group by 1 having max(group) <> min(group) and count(employee_id) = 2 ) select * from two_groups join table1 using (employee_id)
The reason that I am joining it back to the table1 is because I could not add the group and probability columns as a field in the "two_groups" subquery because I didn't want to group by them.
What Can I do to just extract the users being in just exactly two groups?
There is no comments yet
Join our community and get the chance to solve your code issues & share your opinion with usSign up Now