0
這個論壇的新來很容易,我已經迷失在這裏,只想顯示每個名字一行,即喬博客....任何人都可以看到哪裏im因爲目前每個名稱有多行。需要只顯示每個代理名稱一行(SQL)
DECLARE @StartDate DATETIME, @EndDate DATETIME
SELECT @StartDate = '2016-05-31 00:00:01', @EndDate = '2016-05-31 23:00:00'
SELECT CONVERT(Varchar, AgentSession.SessionStart, 103) AS Date,
Agent.Firstname + ' ' + Agent.Lastname AS AgentName,
ProductivitySummary.SessionStartTime As FirstLogin,
ProductivitySummary.SessionEndTime As LastLogin,
ProductivitySummary.PLogOnTime,
(AgentSession.TalkTime + AgentSession.HoldTime + AgentSession.WaitTime + AgentSession.PreviewTime + AgentSession.WrapTime + AgentSession.DeadTime + AgentSession.BreakTime + AgentSession.MealTime + AgentSession.MeetingTime + AgentSession.OtherTime) As LogOnTime,
(AgentSession.TalkTime + AgentSession.HoldTime) As TalkTime,
(AgentSession.WaitTime + AgentSession.PreviewTime) As WaitTime,
(AgentSession.WrapTime + AgentSession.DeadTime) As WrapTime,
AgentSession.BreakTime,
AgentSession.MealTime,
AgentSession.MeetingTime,
AgentSession.OtherTime
FROM Agent INNER JOIN
AgentSession ON Agent.AgentID = AgentSession.AgentID
INNER JOIN(
SELECT CONVERT(Varchar, AgentSession.SessionStart, 103) AS Date,
Agent.AgentID,
Agent.Firstname + ' ' + Agent.Lastname AS AgentName,
MIN(AgentSession.SessionStart) SessionStart,
MIN(CONVERT(CHAR(8), AgentSession.SessionStart, 8)) AS SessionStartTime,
MAX(AgentSession.SessionEnd) SessionEnd,
MAX(CONVERT(CHAR(8), AgentSession.SessionEnd, 8)) AS SessionEndTime,
CASE WHEN SUM(AgentSession.TalkTime + AgentSession.HoldTime + AgentSession.WaitTime + AgentSession.PreviewTime + AgentSession.WrapTime + AgentSession.DeadTime + AgentSession.BreakTime + AgentSession.MealTime + AgentSession.MeetingTime + AgentSession.OtherTime) > DATEDIFF(ss, (MIN(CONVERT(CHAR(8), AgentSession.SessionStart, 8))), (MAX(CONVERT(CHAR(8), AgentSession.SessionEnd, 8)))) THEN SUM(AgentSession.TalkTime + AgentSession.HoldTime + AgentSession.WaitTime + AgentSession.PreviewTime + AgentSession.WrapTime + AgentSession.DeadTime + AgentSession.BreakTime + AgentSession.MealTime + AgentSession.MeetingTime + AgentSession.OtherTime) ELSE DATEDIFF(ss, (MIN(CONVERT(CHAR(8), AgentSession.SessionStart, 8))), (MAX(CONVERT(CHAR(8), AgentSession.SessionEnd, 8)))) END AS PLogOnTime,
SUM(AgentSession.TalkTime + AgentSession.HoldTime + AgentSession.WaitTime + AgentSession.PreviewTime + AgentSession.WrapTime + AgentSession.DeadTime + AgentSession.BreakTime + AgentSession.MealTime + AgentSession.MeetingTime + AgentSession.OtherTime) As LogOnTime,
COUNT(AgentSession.AgentID) Logouts,
SUM(AgentSession.TalkTime + AgentSession.HoldTime) As TalkTime,
SUM(AgentSession.WaitTime + AgentSession.PreviewTime) As WaitTime,
SUM(AgentSession.WrapTime + AgentSession.DeadTime) As WrapTime,
SUM(AgentSession.BreakTime) As BreakTime,
SUM(AgentSession.MealTime) As MealTime,
SUM(AgentSession.MeetingTime) As MeetingTime,
SUM(AgentSession.OtherTime) As OtherTime
FROM Agent INNER JOIN
AgentSession ON Agent.AgentID = AgentSession.AgentID
WHERE (AgentSession.SessionStart Between @StartDate AND @EndDate) AND (Agent.Lastname Not Like '%(DND)')
GROUP BY CONVERT(Varchar, AgentSession.SessionStart, 103), Agent.AgentID, Agent.Firstname + ' ' + Agent.Lastname
)ProductivitySummary
ON CONVERT(Varchar, AgentSession.SessionStart, 103) = ProductivitySummary.Date AND AgentSession.AgentID = ProductivitySummary.AgentID
WHERE (AgentSession.SessionStart Between @StartDate AND @EndDate) AND (Agent.Lastname Not Like '%(DND)')
ORDER BY Agent.Firstname + ' ' + Agent.Lastname ASC, CONVERT(CHAR(8), AgentSession.SessionStart, 8)
是的,我仍然得到它們。儘管我通過SSDT中的分組解決了這個問題。 – wdbacon