Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****** Script for SelectTopNRows command from SSMS ******/
- DECLARE @IVR TABLE(Id uniqueidentifier, IdChain uniqueidentifier, Astr nvarchar(100), Bstr nvarchar(100))
- DECLARE @Operators1 TABLE(Id uniqueidentifier, IdNext uniqueidentifier, IdChain uniqueidentifier, Astr nvarchar(100), Bstr nvarchar(100))
- DECLARE @Operators2 TABLE(Id uniqueidentifier, IdChain uniqueidentifier, Astr nvarchar(100), Bstr nvarchar(100))
- DECLARE @AllOperators TABLE(StrName nvarchar(100))
- --находим звонки поступившие от клиента в IVR и перешедшие дальше
- INSERT INTO @IVR
- SELECT IdNext
- ,IdChain
- ,Astr
- ,Bstr
- FROM [oktell].[dbo].[A_Stat_Connections_1x1]
- WHERE ConnectionType=4 AND IdNext IS NOT NULL
- --находим операторов1 и фильтруем
- INSERT INTO @Operators1
- SELECT [oktell].[dbo].[A_Stat_Connections_1x1].Id
- ,[oktell].[dbo].[A_Stat_Connections_1x1].IdNext
- ,[oktell].[dbo].[A_Stat_Connections_1x1].IdChain
- ,[oktell].[dbo].[A_Stat_Connections_1x1].Astr
- ,[oktell].[dbo].[A_Stat_Connections_1x1].Bstr
- FROM
- @IVR
- INNER JOIN
- [oktell].[dbo].[A_Stat_Connections_1x1]
- ON [oktell].[dbo].[A_Stat_Connections_1x1].Id = [@IVR].Id
- WHERE ConnectionType=5 AND ReasonStop=6 AND IdNext IS NOT NULL
- --находим операторов2 через операторов1
- INSERT INTO @Operators2
- SELECT [oktell].[dbo].[A_Stat_Connections_1x1].Id
- ,[oktell].[dbo].[A_Stat_Connections_1x1].IdChain
- ,[oktell].[dbo].[A_Stat_Connections_1x1].Astr
- ,[oktell].[dbo].[A_Stat_Connections_1x1].Bstr
- FROM
- @Operators1
- INNER JOIN
- [oktell].[dbo].[A_Stat_Connections_1x1]
- ON [oktell].[dbo].[A_Stat_Connections_1x1].Id = [@Operators1].IdNext
- --соединяем операторов1 и опреаторов2
- INSERT INTO @AllOperators
- SELECT [@Operators1].Bstr
- --,[@Operators2].Bstr
- --,[@Operators1].Astr
- --,[@Operators2].Astr
- FROM @Operators1
- INNER JOIN
- @Operators2
- ON [@Operators1].IdChain = [@Operators2].IdChain
- --подсчет количества переводов
- SELECT [@AllOperators].StrName
- ,COUNT([@AllOperators].StrName) AS Count_Of_Transfers
- FROM @AllOperators
- GROUP BY [@AllOperators].StrName
- ORDER BY COUNT([@AllOperators].StrName) DESC
Advertisement
Add Comment
Please, Sign In to add comment