Create select with various conditions

1

I have a table with several connections record and I need to make some conditions to separate records.

I already use select to validate information

SELECT  count(*) as qtdade_status_dia,

        "TB_BASE_ACIONAMENTO".contrato || "TB_BASE_ACIONAMENTO".telefone || "TB_BASE_ACIONAMENTO".data_registro AS contrato_telefone_data_registro,
        "TB_BASE_ACIONAMENTO".data_registro,
        "TB_BASE_ACIONAMENTO".contrato,
        "TB_BASE_ACIONAMENTO".telefone,
        "TB_BASE_ACIONAMENTO".tipo_discagem,
        "TB_BASE_ACIONAMENTO".status_telefonia

        FROM "TB_BASE_ACIONAMENTO"
        GROUP BY 

        contrato_telefone_data_registro,
        "TB_BASE_ACIONAMENTO".data_registro,
        "TB_BASE_ACIONAMENTO".contrato,
        "TB_BASE_ACIONAMENTO".telefone,
        "TB_BASE_ACIONAMENTO".tipo_discagem,
        "TB_BASE_ACIONAMENTO".status_telefonia

        HAVING COUNT(*) >=3

From this query that is actually a view I make queries on it.

You would need to count the status_telefonia field along with the above rules and then make a select similar to the one below:

 SELECT * FROM "public"."VW_BS_TESTE" 

 WHERE "status_telefonia" = ' MACHINE' 

 OR "status_telefonia" = ' INVALID NUMBER' 

 AND "qtdade_status_dia" > '5' 

 AND "status_telefonia" NOT LIKE '% HANDLED%'

 AND  "data_registro" >= '01/01/2017' 

 AND "data_registro" <= '23/02/2017' 

 AND "tipo_discagem" = 'OUTBOUND'

If you do not find the result in the above query, you would do the following query:

SELECT * FROM "public"."VW_BS_TESTE" 

WHERE "status_telefonia" = ' BUSY' 

AND "qtdade_status_dia" >= '3' 

AND "status_telefonia" NOT LIKE '% HANDLED%'

AND  "data_registro" >= '01/01/2017' 

AND "data_registro" <= '23/02/2017' 

AND "tipo_discagem" = 'OUTBOUND'

I would like to create a query that would do in a single process to speed up the process. Could someone help me?

    
asked by anonymous 07.03.2017 / 20:23

1 answer

0

With UNION it recognizes only the first SELECT, outside that would also need to group Status_Telephony to perform the query before, could not use some kind of condition?

    
08.03.2017 / 21:32