我假设您的意思是几个位列,而不是标志列。
我建议不要使用 bit,因为您需要将它们与 sum 或 max 相加。所以你应该使用整数,以便不必转换/转换。
T_组:
GRP_ID
GRP_Name
GRP_IsAdmin AS integer
GRP_IsModerator AS integer
GRP_IsGuest AS integer
T_Users
USR_ID
USR_DisplayName
USR_UserName
USR_PasswordHash
USR_PassWordSalt
USR_PassWordAlgorithm
T_MAP_Users_Groups
MAP_USRGRP_ID
MAP_USRGRP_USR_ID
MAP_USRGRP_GRP_ID
像这样查询:
SELECT
USR_ID, USR_Name
,MAX(GRP_IsAdmin) AS IsAdmin
,MAX(GRP_IsModerator) AS IsModerator
,MAX(GRP_IsGuest) AS IsGuest
FROM T_Users
LEFT JOIN T_MAP_Users_Groups
ON MAP_USRGRP_USR_ID = USR_ID
LEFT JOIN T_Groups
ON GRP_ID = MAP_USRGRP_GRP_ID
GROUP BY USR_ID, USR_Name