Answer the question
In order to leave comments, you need to log in
How to add two separate lines to the total query and the sum of the total input, without union?
select
q."Operators" as "Operators",
q."Incoming" as "Incoming conversation over 1 sec.",
q."Manual Outgoing" as "Manual Outgoing dialing",
q."Outgoing campaign" as "Outgoing campaign ",
q."Lost" as "Lost",
q."Total" as "Total incoming",
from (select
coalesce(s."B2IDUser", s."AIDUser",s."B3IDUser") as "Operators" ,
count(s."ID") filter (where s."SeanceType" = 1 and "DurationTalk">0 ) as "Incoming",
count(s."ID") filter (where s."SeanceType" = 2 ) as"Manual Outgoing",
count(s."ID") filter (where s."SeanceType" = 2 and ("ANumber" like '%z%' or "B2IDUser" in (
5667834207, 5511332770, 5667834203, 5022050645, 5022050649,
5022050661, 5022050691, 5026073792, 5030972556, 5041139142,
5154248810, 5022050687, 5022050657, 5030698089, 6051167175,
5578934994, 5667834199, 6071889612, 5698847426, 5022050675,
5026918771, 5027841073, 5148236948, 5022050669, 5613031592
) ) ) as "Outgoing campaign",
count(s."ID") filter (where s."SeanceResult" = 191) as "Lost",
count(s.*) filter (where s."SeanceType" =1) as "Total",
count(s."ID") filter (where s."SeanceResult" in (192, 101, 102, 191, 151)) as "Percent"
from "S_Seances"s
where
(
s."B2IDUser" in (
5667834207, 5511332770, 5667834203, 5022050645, 5022050649,
5022050661, 5022050691, 5026073792, 5030972556, 5041139142,
5154248810, 5022050687, 5022050657, 5030698089, 6051167175,
5578934994, 5667834199, 6071889612, 5698847426, 5022050675,
5026918771, 5027841073, 5148236948, 5022050669, 5613031592
) or
s. "AIDUser" in (
5667834207, 5511332770, 5667834203, 5022050645, 5022050649,
5022050661, 5022050691, 5026073792, 5030972556, 5041139142,
5154248810, 5022050687, 5022050657, 5030698089, 6051167175,
5578934994, 5667834199, 6071889612, 5698847426, 5022050675,
5026918771, 5027841073, 5148236948, 5022050669, 5613031592
) or
s. "B3IDUser" in (
5667834207, 5511332770, 5667834203, 5022050645, 5022050649,
5022050661, 5022050691, 5026073792, 5030972556, 5041139142,
5154248810, 5022050687, 5022050657, 5030698089, 6051167175,
5578934994, 5667834199, 6071889612, 5698847426, 5022050675,
5026918771
,
5027841073 ,
5148236948
, 5022050669,
5613031592
) "Incoming",q."Percent",q."Total",q."Manual Outgoing",q."Outgoing campaign"
Answer the question
In order to leave comments, you need to log in
Added group by ROLLUP(1) , now the question is how to read % on the basis of the total number in the line and write it in a new column, 100 / the number that we received and multiply by the number of operator calls. Question how to pull out this number in request?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question