pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: ivan@adicional.com.br
Cc: pgsql-bugs@postgresql.org
Subject: Re: problem in sql - sum()
Date: Tue, 22 Mar 2016 17:25:27 -0300
Message-ID: <20160322202527.GA510502@alvherre.pgsql> (raw)
In-Reply-To: <206706195.1632677.1458657729534.JavaMail.zimbra@adicional.com.br>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (5+ messages)  latest in thread

Message-ID: <20160322202527.GA510502@alvherre.pgsql>
Permalink:  ../20160322202527.GA510502@alvherre.pgsql/
Also on:    postgresql.org/message-id/20160322202527.GA510502@alvherre.pgsql

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: alvherre@2ndquadrant.com, ivan@adicional.com.br
  Subject: Re: problem in sql - sum()
  In-Reply-To: <20160322202527.GA510502@alvherre.pgsql>
  References: <206706195.1632677.1458657729534.JavaMail.zimbra@adicional.com.br> <20160322202527.GA510502@alvherre.pgsql>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox