Sql server sql server存储过程获取参与事件的人数

Sql server sql server存储过程获取参与事件的人数,sql-server,stored-procedures,Sql Server,Stored Procedures,我需要显示响应“是”以参加活动的人数。以下是我迄今为止的SELECT声明: SELECT TOP (100) PERCENT dbo.tb_EventAttendance.WillAttend, dbo.tb_Events.EventName, dbo.tb_Events.EventDate FROM dbo.tb_EventAttendance INNER JOIN dbo.tb_Events ON dbo.tb_EventAttendance.EventID = db

我需要显示响应“是”以参加活动的人数。以下是我迄今为止的SELECT声明:

SELECT TOP (100) PERCENT
    dbo.tb_EventAttendance.WillAttend,
    dbo.tb_Events.EventName,
    dbo.tb_Events.EventDate
FROM dbo.tb_EventAttendance
INNER JOIN dbo.tb_Events ON dbo.tb_EventAttendance.EventID = dbo.tb_Events.dbID
WHERE (dbo.tb_EventAttendance.WillAttend = 'Y')
ORDER BY dbo.tb_Events.EventDate

我是否使用计数功能?如果是,在这种情况下具体如何使用?

您需要同时使用计数和分组依据(因为聚合计数):

我希望返回的总数是“dbo.tb_eventAttention.willAttention”。
SELECT TOP (100) PERCENT dbo.tb_Events.EventName, dbo.tb_Events.EventDate,
COUNT(dbo.tb_EventAttendance.WillAttend) as NumAttendees, 
FROM  dbo.tb_EventAttendance INNER JOIN
dbo.tb_Events ON dbo.tb_EventAttendance.EventID = dbo.tb_Events.dbID
WHERE     (dbo.tb_EventAttendance.WillAttend = 'Y')
GROUP BY dbo.tb_EventName, dbo.tb_Events.EventDate
ORDER BY dbo.tb_Events.EventDate