Problem with dates in PostgreSQL

1

I have this query below and I want the faturamento , ticket_medio and qtd_pecas , qtd_atendimentos , to be divided by the numbers on Tuesdays. Example had 5 Tuesdays with values registered in this view, I want it to be divided by 5.

What postgres function can I use?

SELECT
    id_empresa,
    id_loja,
    sum(faturamento),
    sum(ticket_medio),
    sum(qtd_pecas),
    sum(qtd_atendimentos)
FROM
    sumario_diario
WHERE
    to_char(data_sumario, 'dy') = 'tue'
    AND id_loja = 19
GROUP BY
    id_empresa,
    id_loja;
    
asked by anonymous 10.08.2017 / 17:40

2 answers

0

Getting the answer, it looks like this:

SELECT  id_empresa, id_loja, avg(faturamento), avg(ticket_medio), avg(qtd_pecas),avg(qtd_atendimentos) FROM sumario_diario

where TO_CHAR (date_summary, 'dy') = 'tue' and id_loja = 19 group by business_id, business_id

    
10.08.2017 / 19:43
0

See if this resolves

SELECT
    id_empresa,
    id_loja,
    sum(faturamento),
    sum(ticket_medio),
    sum(qtd_pecas),
    sum(qtd_atendimentos),

    avg(faturamento) as fat_terca,
    avg(ticket_medio) as ticket_terca,
    avg(qtd_pecas) as pecas_terca,
    avg(qtd_atendimentos) as aten_terca

FROM
    sumario_diario
WHERE
    to_char(data_sumario, 'dy') = 'tue'
    AND id_loja = 19
GROUP BY
    id_empresa,
    id_loja;

Click here to run the Test!

    
10.08.2017 / 20:03