WorkAkkaunt

Отчет по переводам

Jun 27th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.22 KB | None | 0 0
  1. /****** Script for SelectTopNRows command from SSMS  ******/
  2. DECLARE @IVR TABLE(Id uniqueidentifier, IdChain uniqueidentifier, Astr nvarchar(100), Bstr nvarchar(100))
  3. DECLARE @Operators1 TABLE(Id uniqueidentifier, IdNext uniqueidentifier, IdChain uniqueidentifier, Astr nvarchar(100), Bstr nvarchar(100))
  4. DECLARE @Operators2 TABLE(Id uniqueidentifier, IdChain uniqueidentifier, Astr nvarchar(100), Bstr nvarchar(100))
  5. DECLARE @AllOperators TABLE(StrName nvarchar(100))
  6.  
  7. --находим звонки поступившие от клиента в IVR и перешедшие дальше
  8. INSERT INTO @IVR
  9. SELECT IdNext
  10.     ,IdChain
  11.     ,Astr
  12.     ,Bstr
  13.   FROM [oktell].[dbo].[A_Stat_Connections_1x1]
  14.   WHERE ConnectionType=4 AND IdNext IS NOT NULL
  15.  
  16. --находим операторов1 и фильтруем
  17. INSERT INTO @Operators1
  18. SELECT [oktell].[dbo].[A_Stat_Connections_1x1].Id
  19.     ,[oktell].[dbo].[A_Stat_Connections_1x1].IdNext
  20.     ,[oktell].[dbo].[A_Stat_Connections_1x1].IdChain
  21.     ,[oktell].[dbo].[A_Stat_Connections_1x1].Astr
  22.     ,[oktell].[dbo].[A_Stat_Connections_1x1].Bstr
  23. FROM
  24.   @IVR
  25.   INNER JOIN
  26.   [oktell].[dbo].[A_Stat_Connections_1x1]
  27.     ON [oktell].[dbo].[A_Stat_Connections_1x1].Id = [@IVR].Id
  28.     WHERE ConnectionType=5 AND ReasonStop=6 AND IdNext IS NOT NULL
  29.  
  30. --находим операторов2 через операторов1
  31. INSERT INTO @Operators2
  32. SELECT [oktell].[dbo].[A_Stat_Connections_1x1].Id
  33.     ,[oktell].[dbo].[A_Stat_Connections_1x1].IdChain
  34.     ,[oktell].[dbo].[A_Stat_Connections_1x1].Astr
  35.     ,[oktell].[dbo].[A_Stat_Connections_1x1].Bstr
  36. FROM
  37.   @Operators1
  38.   INNER JOIN
  39.   [oktell].[dbo].[A_Stat_Connections_1x1]
  40.     ON [oktell].[dbo].[A_Stat_Connections_1x1].Id = [@Operators1].IdNext
  41.  
  42. --соединяем операторов1 и опреаторов2
  43. INSERT INTO @AllOperators
  44. SELECT [@Operators1].Bstr
  45.     --,[@Operators2].Bstr
  46.     --,[@Operators1].Astr
  47.     --,[@Operators2].Astr
  48. FROM @Operators1
  49.     INNER JOIN
  50.     @Operators2
  51.     ON [@Operators1].IdChain = [@Operators2].IdChain
  52.  
  53. --подсчет количества переводов
  54. SELECT [@AllOperators].StrName
  55.     ,COUNT([@AllOperators].StrName) AS Count_Of_Transfers
  56. FROM @AllOperators
  57. GROUP BY [@AllOperators].StrName
  58. ORDER BY COUNT([@AllOperators].StrName) DESC
Advertisement
Add Comment
Please, Sign In to add comment