这是我获取总数的查询。
SELECT
MemberShipMaster.Id,
MemberShipMaster.Name,
TotalCount =
(
SELECT
ISNULL(COUNT(MemberPortfolio.Id), 0) AS total
FROM
JFPMembers
INNER JOIN MemberPortfolio
ON JFPMembers.MemberID = MemberPortfolio.MemberId
WHERE
JFPMembers.MembershipType = MemberShipMaster.Id
AND JFPMembers.IsActive = 1
AND MemberPortfolio.IsActive = 1
)
FROM
MemberShipMaster
Left JOIN JFPMembers
ON MemberShipMaster.Id = JFPMembers.MembershipType
WHERE
MemberShipMaster.Id <> 6
GROUP BY
MemberShipMaster.Id,
MemberShipMaster.Name
Order by
MemberShipMaster.Name
下面是我的表架构
SELECT [MemberID] -- PK
,[MembershipType] --FK , table [MemberShipMaster]
FROM JFPMembers
SELECT [Id] -- PK
,[MemberId] -- FK OF Table JFPMembers
FROM MemberPortfolio
SELECT [Id] --PK
,[Name]
FROM MemberShipMaster
我需要的是成员 Portfolios 的总计数,按 MembershipType,即我的关系是这样的,JFPMembers 是保存成员信息的主表。会员分为 3 类,高级会员、企业会员和普通会员。这三种类型存储在 MemberShipMaster 中。ID 分别为 3、4 和 5。还有一张用于持有 Portfolio 的表,该表作为 MemberId 来关联其各自的成员。
但是我收到了 MemberShipMaster.Id 的一些多值或参考错误。请帮我...