!

.

2
27 ,
6
2
39
100% 35%
2

, . , , . .
, - ( ).

. , - .

SELECT DISTINCT --su.ID suId,IIF (u.Alias IS NULL,u.UserName,u.Alias),u.ID, A.DateTime, IIF (A.URL IS NULL, A.Application, A.URL),A.TypeActivity, A.ActiveTime, A.InactiveTime,
(select MIN(DateTime) from Activity Amin WHERE Amin.UserID = A.UserId AND CAST(DATEADD(mi,u.GMTOffset,Amin.DateTime) as Date) = CAST(DATEADD(mi,u.GMTOffset,A.DateTime) As Date)),u.GroupID,A.ApplicationPath,u.IPJson,u.GMTOffset

FROM

(SELECT AA.UserId,Max(AA.DateTime) As MaxDateTime from Activity AS AA INNER JOIN Users AS U ON U.ID=UserID WHERE (AA.SprutUsersID=@sprutusersid AND DATEADD(mi,u.GMTOffset, AA.DateTime) BETWEEN @datefrom AND @dateto) GROUP BY AA.USerId) AMAX

INNER JOIN Activity A ON AMAX.UserID = A.UserId AND AMAX.MaxDateTime = A.DateTime
INNER JOIN Users U ON A.UserID = U.ID
LEFT JOIN Groups G ON U.GroupID = G.ID

WHERE

(a.SprutUsersID=@SprutUsersId) AND (u.Removed IS NULL)

 .
. 
37 ,
2
2
2

« »

.
.
.
.
.