Hello Everyone
I want to get all user and their active cases, and then find which user have less number of cases
i have write the following sql query , i want to implement that in work, how can i write using query expression or how can i use it ?
SELECT TOP(1) a.SystemUserId, a.FullName, MIN(a.[Total]) AS total FROM (
SELECT us.SystemUserId,us.fullname,
COUNT(*) AS [Total]
FROM SystemUserBase AS us
LEFT JOIN IncidentBase AS ca
ON us.SystemUserId = ca.OwnerID
WHERE
StateCode=0
GROUP BY us.Fullname,SystemUserId
HAVING SystemUserId in (SELECT SystemUserId FROM TeamMembership WHERE TeamId = 'd6ae0aab-d60a-e711-9401-0050569b1ee7')
)a
GROUP BY a.FullName,a.Total,a.SystemUserId
ORDER BY total ascending