A
A
Alexey rambest2019-06-07 10:15:26
PostgreSQL
Alexey rambest, 2019-06-07 10:15:26

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"
5cfa0f0a42649924345882.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery, 2019-06-07
@Desay

Through nested queries

A
Alexey rambest, 2019-06-07
@waff_inf

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?5cfa1f2fa9f9f458435646.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question