Re: problem in sql - sum() - Mailing list pgsql-bugs

From Alvaro Herrera
Subject Re: problem in sql - sum()
Date
Msg-id 20160322202527.GA510502@alvherre.pgsql
Whole thread Raw
In response to problem in sql - sum()  (ivan@adicional.com.br)
Responses Re: problem in sql - sum()
List pgsql-bugs
ivan@adicional.com.br wrote:
> Hi. I have a problem identified.
> In select :
>
> select data_carteira, sum(valor_carteira) from carteira where
> data_carteira between '2016-01-01' and '2016-02-18'
> GROUP BY data_carteira order by data_carteira
>
> return a values from month. In the day 18, return the value 82.915.213,14.

This query means "the sum of all values for all the days between Jan 1st
and Feb 18th".

> Now, if I use the select :
> select data_carteira, sum(valor_carteira) from carteira where
> data_carteira='2016-01-18'
> GROUP BY data_carteira order by data_carteira

"The sum of all values for Jan 18th".

> return 103.629.305,96.
>
> It's very diferenty.

I don't understand why you think this is a problem.  The values in that
table could be anything --- What this says is that there are rows for
the 2016-01-18 date that add up exactly to 103.629.305,96; and the
values for the other dates add to -20.714.093,82.

> Only change is date.

Right.

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: problem in sql - sum()
Next
From: xenophon@irtnog.org
Date:
Subject: BUG #14040: Cannot authenticate against Active Directory in search+bind mode using domain root naming context