tsql 不同计数子查询2
我正在使用 SSMS 2008,我需要使用子查询来返回唯一记录/客户端的计数。我该怎么做?目前我收到错误:
Msg 512, Level 16, State 1, Line 58
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or
这是我目前的伪代码:
SELECT A.Program, A.PEOPLE_ID, K.EVENT_NAME, A.Program2, A.Program3
(SELECT COUNT(DISTINCT K.EVENT_NAME)
FROM #TEMP1 A, evolv_cs.dbo.facility_view F, evolv_cs.dbo.people_x N, event_view K WITH (NOLOCK)
WHERE F.group_profile_id = A.group_profile_id AND
K.event_definition_id = a.event_definition_id AND
A.people_id = N.people_id
GROUP BY K.EVENT_NAME) as DistinctEvent
FROM #TEMP1 A
JOIN event_view K WITH (NOLOCK) on K.event_definition_id = A.event_definition_id
WHERE @START_DATE BETWEEN A.Enrolled_Date AND DATEADD(D, 14, A.Enrolled_Date)
AND (@SERVICE IS NULL OR @SERVICE = K.event_name)
GROUP BY
A.Program, A.PEOPLE_ID, K.EVENT_NAME, A.Program2, A.Program3
I am using SSMS 2008 and I need to use a subquery to return the count of unique records / client. How do I do this? Currently I am getting the error:
Msg 512, Level 16, State 1, Line 58
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or
Here is my pseudocode currently:
SELECT A.Program, A.PEOPLE_ID, K.EVENT_NAME, A.Program2, A.Program3
(SELECT COUNT(DISTINCT K.EVENT_NAME)
FROM #TEMP1 A, evolv_cs.dbo.facility_view F, evolv_cs.dbo.people_x N, event_view K WITH (NOLOCK)
WHERE F.group_profile_id = A.group_profile_id AND
K.event_definition_id = a.event_definition_id AND
A.people_id = N.people_id
GROUP BY K.EVENT_NAME) as DistinctEvent
FROM #TEMP1 A
JOIN event_view K WITH (NOLOCK) on K.event_definition_id = A.event_definition_id
WHERE @START_DATE BETWEEN A.Enrolled_Date AND DATEADD(D, 14, A.Enrolled_Date)
AND (@SERVICE IS NULL OR @SERVICE = K.event_name)
GROUP BY
A.Program, A.PEOPLE_ID, K.EVENT_NAME, A.Program2, A.Program3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以更有效地工作和运行。
This should work and run more efficiently.