sql - Segregation of Duties search -


i'm trying write sql statement search table segregation of duties of issues. in table there user column , responsibility column. want pull users have 2 defined responsibilities. trying, not work:

select users.[user], users.[responsibility]   users  users.[responsibility]="example a"    , users.[responsibility]="example b"; 

any suggestions? think it's not working because it's not basing responsibilities on user, i'm not sure how fix that.

the following query return list of users having both 'example a' , 'example b' responsibility:

select users.[user] users group [user] having count(case when [responsibility]='example a' 1 end) >= 1 ,        count(case when [responsibility]='example b' 1 end) >= 1 

sql fiddle demo here

if want users having @ least 2 different responsibilities (no matter which), substitute having clause by:

having count(distinct [responsibility]) >= 2 

edit:

use following query ms-access:

select user users group user having  sum(iif(responsibility = "example a", 1, 0)) >=1          ,  sum(iif(responsibility = "example b", 1, 0)) >= 1 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -