How to add two separate lines in the damn request and just amount from All the incoming, without the union?

select
q."Operators" as "Operators,"
q."Incoming" as "Incomming conversation for more than 1 sec.",
q."Manual Outgoing" as "Manual Outbound dial"
q."Outgoing campaign" as "Outgoing through the campaign",
q."Lost" as "Lost",
q."Total" as "Total inbound",



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 (the 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
)
) and
s."TimeStart" >= current_date
group by 1 ) as
q
group by q."Operators"q."Lost",q."Incoming",q."Percent",q."Total" ,q."Manual Outgoing",q."Outgoing campaign"5cfa0f0a42649924345882.png
March 23rd 20 at 19:29
2 answers
March 23rd 20 at 19:31
Using subqueries
The question of his stuff at the top or bottom ? - Marco_Daugherty commented on March 23rd 20 at 19:34
March 23rd 20 at 19:33
Added group by ROLLUP(1) , the question as now on the basis of the total number in the line to read % and write in a new column, 100/number who received and multiplied by the number of calls of the operator. The question how to pull that number in a query ?5cfa1f2fa9f9f458435646.png

Find more questions by tags SQLPostgreSQL