如何获取团队的月度和季度数据

时间:2017-08-18 16:00:44

标签: sql

我希望能够生成一份报告,显示当前提交的调查月份与调查的总季度相比。我需要该语句能够每月添加报告导出的月度金额。有谁知道怎么做到这一点?

SELECT UA.FirstName
    ,UA.LastName
    ,COUNT(S.Year) AS TotalStudies
    ,(SELECT COUNT(S.Year) 
    FROM ParentInfo P
    LEFT JOIN Survey S ON P.SurveyId=S.SurveyId
    LEFT JOIN CooperationLevel CL ON P.SurveyId=CL.SurveyID
    LEFT JOIN SurveyAccess SA ON P.SurveyId=SA.SurveyId
    LEFT JOIN UserAccount UA ON SA.UserId=UA.UserId
    WHERE S.Year=Year(GETDATE()) 
    AND (CL.CIOISCooperation=1 OR CL.CIOISPartialCooperation=1) 
    AND  UA.UserId in (73699)
    GROUP BY UA.FirstName,UA.LastName,SA.UserId) AS Cooperation
    ,(SELECT COUNT(S.Year) AS NoCooperation
    FROM ParentInfo P
    LEFT JOIN Survey S ON P.SurveyId=S.SurveyId
    LEFT JOIN CooperationLevel CL ON P.SurveyId=CL.SurveyID
    LEFT JOIN SurveyAccess SA ON P.SurveyId=SA.SurveyId
    LEFT JOIN UserAccount UA ON SA.UserId=UA.UserId
    WHERE S.Year=Year(GETDATE()) 
    AND ((CL.CIOISCooperation=0 AND CL.CIOISPartialCooperation=0) OR CL.CIOISCooperation IS NULL AND CL.CIOISPartialCooperation IS NULL) 
    AND  UA.UserId in (73699)
    GROUP BY SA.UserId) AS NoCooperation
    FROM ParentInfo P
    LEFT JOIN Survey S ON P.SurveyId=S.SurveyId
    LEFT JOIN CooperationLevel CL ON P.SurveyId=CL.SurveyID
    LEFT JOIN SurveyAccess SA ON P.SurveyId=SA.SurveyId
    LEFT JOIN UserAccount UA ON SA.UserId=UA.UserId
    WHERE S.Year=Year(GETDATE()) 
    AND  UA.UserId in (73699)
    GROUP BY UA.FirstName,UA.LastName,SA.UserId

当前查询仅提供个别调查而非汇总。

0 个答案:

没有答案