Распределение операторов по статусам — различия между версиями
Материал из Oktell
Строка 15: | Строка 15: | ||
FROM | FROM | ||
(SELECT u.id, u.name , | (SELECT u.id, u.name , | ||
− | coalesce((select top 1 s.state from A_UserStateHistory s WHERE s.UserId = u.id ORDER BY s.TimeChange DESC),0) [state] | + | coalesce((select top 1 s.state from A_UserStateHistory s |
+ | WHERE s.UserId = u.id and cast(s.TimeChange as DATE) = cast(getdate() as DATE) | ||
+ | ORDER BY s.TimeChange DESC),0) [state] | ||
FROM A_Users u | FROM A_Users u | ||
where u.id in (select OperatorId from [oktell_settings].[dbo].[A_TaskManager_Operators] | where u.id in (select OperatorId from [oktell_settings].[dbo].[A_TaskManager_Operators] |
Версия 12:38, 27 августа 2014
Запрос показывает распределение операторов Call-центра по статусам "Готов", "Занят" и "Перерыв". В запросе имеется закомментированная строка для фильтрации данных по конкретной задаче.
SELECT sum( CASE WHEN state = 1 THEN 1 ELSE 0 END) [Готов] ,sum( CASE WHEN state = 2 THEN 1 ELSE 0 END) [Перерыв] ,sum( CASE WHEN state = 5 or state=6 THEN 1 ELSE 0 END) [Занят] ,sum( CASE WHEN state = 0 THEN 1 ELSE 0 END) [Отключен] ,sum( CASE WHEN state = 3 THEN 1 ELSE 0 END) [Нет на месте] ,sum( CASE WHEN state = 7 THEN 1 ELSE 0 END) [Без телефона] FROM (SELECT u.id, u.name , coalesce((select top 1 s.state from A_UserStateHistory s WHERE s.UserId = u.id and cast(s.TimeChange as DATE) = cast(getdate() as DATE) ORDER BY s.TimeChange DESC),0) [state] FROM A_Users u where u.id in (select OperatorId from [oktell_settings].[dbo].[A_TaskManager_Operators] -- where TaskId='25130D79-8766-4EAD-9C22-596CF2B465F9' ) )j