我正在 SQL Server 2008 中创建一个 SSRS 报告。结果表根据业务部门进行分组。我的要求是在每组设置后显示总和。
这是查询:
SELECT
DATENAME(MONTH, A.scheduledstart) Months
,A.scheduledstart ScheduledStart
,B.name BusinessUnit
,CASE WHEN FC.renre_topbrokername='Yes' THEN 'Broker'
WHEN FC.renre_typevendorpartner<>0 THEN 'Vendor'
WHEN FC.renre_typemediacontact<>0 THEN 'Media'
WHEN FC.renre_typeinvestmentmanager<>0 THEN 'Investment Manager'
WHEN FC.renre_typeclient<>0 THEN 'Client'
WHEN FC.renre_typeinvestor<>0 THEN 'Investor'
WHEN FC.renre_typemitigationresources<>0 THEN 'Mitigation'
WHEN FC.renre_typeriskaccountingsp<>0 THEN 'Risk/Accounting Services Provider'
WHEN FC.renre_typeindustryanalyst<>0 THEN 'Industry Analyst'
WHEN FC.renre_typeratingagencies<>0 THEN 'Rating Agency'
WHEN FC.renre_typecommunity<>0 THEN 'Community'
WHEN FC.renre_typeresearchprovider<>0 THEN 'Research Provider'
WHEN FC.renre_typefederal<>0 THEN 'Federal, State or Local Regulator'
WHEN FC.renre_typeindustryassociation<>0 THEN 'Industry Association'
WHEN FC.renre_typeboardmember<>0 THEN 'Board Member'
WHEN FC.renre_typeinvestmentbank<>0 THEN 'Investment Bank'
END AttendeeType
,AP.partyidname Name
,CASE WHEN FC.renre_keycontact=0 THEN 'No' ELSE 'Yes' END isKeyContact
,A.owneridname Owner
,COUNT(AP.partyidname) AttendeeCount
from
FilteredAppointment A JOIN FilteredBusinessUnit B
ON A.owningbusinessunit=B.businessunitid
JOIN FilteredActivityParty AP ON A.activityid = AP.activityid
JOIN FilteredContact FC ON FC.contactid = AP.partyid
WHERE
A.scheduledstart='2014-05-31 15:00:00.000'
and
AP.participationtypemask=6
group by B.name,A.scheduledstart,AP.partyidname,
CASE WHEN FC.renre_topbrokername='Yes' THEN 'Broker'
WHEN FC.renre_typevendorpartner<>0 THEN 'Vendor'
WHEN FC.renre_typemediacontact<>0 THEN 'Media'
WHEN FC.renre_typeinvestmentmanager<>0 THEN 'Investment Manager'
WHEN FC.renre_typeclient<>0 THEN 'Client'
WHEN FC.renre_typeinvestor<>0 THEN 'Investor'
WHEN FC.renre_typemitigationresources<>0 THEN 'Mitigation'
WHEN FC.renre_typeriskaccountingsp<>0 THEN 'Risk/Accounting Services Provider'
WHEN FC.renre_typeindustryanalyst<>0 THEN 'Industry Analyst'
WHEN FC.renre_typeratingagencies<>0 THEN 'Rating Agency'
WHEN FC.renre_typecommunity<>0 THEN 'Community'
WHEN FC.renre_typeresearchprovider<>0 THEN 'Research Provider'
WHEN FC.renre_typefederal<>0 THEN 'Federal, State or Local Regulator'
WHEN FC.renre_typeindustryassociation<>0 THEN 'Industry Association'
WHEN FC.renre_typeboardmember<>0 THEN 'Board Member'
WHEN FC.renre_typeinvestmentbank<>0 THEN 'Investment Bank'
END
,FC.renre_keycontact
,CASE WHEN FC.renre_keycontact=0 THEN 'No' ELSE 'Yes' END
,A.owneridname
这是输出:
在输出的第 8 行,我需要在 column 下打印该组中的记录总数(即 7 条)AttendeeCount
。可以有多个组集,因此在这种情况下,总计数将在每个组之后。
请帮忙。