我的查询有问题,我希望它返回我的结果集为 Year = 2013, Month = 1 但每个用户每个月只有一行,当月的登录时间总计,我认为问题是与我的分组:
SELECT YEAR(UP_Date) AS 'Year',
MONTH(UP_Date) AS 'Month',
SUM(ISNULL(UP_UserID,0)) AS UserID,
U_UserName AS UserName,
UP_AveCallTime AS AveCallTime,
UP_TotCallTime AS TotCallTime,
CAST(DATEDIFF(DAY,UP_LogOn, UP_LogOff) AS varchar) + ':' +
CAST(DATEDIFF(HOUR,UP_LogOn, UP_LogOff) AS varchar) + ':' +
CAST(DATEDIFF(MINUTE,UP_LogOn,UP_LogOff) AS varchar) AS [HoursOfMonth]
FROM [RPT_User_Performance_Data_cus]
INNER JOIN Users us ON
UP_UserID = us.ID
GROUP BY Year(UP_Date), MONTH(UP_Date), UP_AveCallTime, UP_TotCallTime, U_UserName, UP_LogOn, UP_LogOff
------Result I Get----------------------------
Year Month UserID UserName AveCallTime TotCallTime HoursOfMonth
2013 6 18552 BossJobs NULL NULL 0:0:4
2013 6 18552 BossJobs NULL NULL 0:0:02
2013 6 18552 BossJobs NULL NULL 0:3:21
2013 6 18552 BossJobs NULL NULL 0:5:01
2013 6 18552 BossJobs NULL NULL NULL
2013 6 18553 KingGates NULL NULL 0:0:2
2013 6 18553 KingGates NULL NULL 0:1:31
-------Instead of ---------------------
Year Month UserID UserName AveCallTime TotCallTime HoursOfMonth
2013 6 18552 BossJobs NULL NULL 0:5:24
2013 6 18553 KingGates NULL NULL 0:1:33