我想选择具有角色 A 和/或 B 但没有角色 c 的用户。我试过这个查询,但它不起作用。
SELECT User from table1 where (role ="A" or role = "B") and (Role <> "C").
用户可以拥有多个角色。然后可以有ABC,AC,AB...
谢谢各位 我想通了
SELECT DISTINCT a.User, a.ROLE
FROM table1 AS a
WHERE (((a.User) Not In (select user from table1 where
ROLE = "ROLEC" and user = a.user)) AND ((a.ROLE)="ROLEA" Or (a.ROLE)="ROLEB")
ORDER BY a.User;
我认为如果你只是省略role <> "C"
它只会得到带有role=A and role=B
. 此外,查看文档,您的括号似乎(role ="A" or role = "B")
是不必要的。