我在数据库中有两个表
profilePermission =>列(profileid,permissionid,profilename)
权限=>列(permissionid,permissionname)
每个配置文件可以具有多个权限。 (例如,个人资料1可以具有权限1,权限2,权限3,个人资料2可以具有权限3,权限2
我想编写一个查询,以获取具有权限.permissionname =权限1和权限.permissionname!= permission2的profileid的计数。
我尝试过类似的事情
select profileid
from CrmProfilePermissions
join CrmPermissions on CrmProfilePermissions.permissionid=CrmPermissions.permissionid
where name in ('permission1') and name not in('permission2')
group by (profileid).
但是没有用。
您缺少聚合函数count()
select profileid, count(1) as cnt
from CrmProfilePermissions
join CrmPermissions on CrmProfilePermissions.permissionid=CrmPermissions.permissionid
where name in ('permission1') and name not in('permission2')
group by (profileid)