Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aiSsc-00061L-TH for pgsql-bugs@arkaria.postgresql.org; Tue, 22 Mar 2016 20:26:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1aiSsc-0004dy-AX for pgsql-bugs@arkaria.postgresql.org; Tue, 22 Mar 2016 20:26:18 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1aiSry-0002SZ-07 for pgsql-bugs@postgresql.org; Tue, 22 Mar 2016 20:25:38 +0000 Received: from smtp-auth.no-ip.com ([8.23.224.61] helo=out.smtp-auth.no-ip.com) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1aiSru-0003kE-Ux for pgsql-bugs@postgresql.org; Tue, 22 Mar 2016 20:25:36 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [200.83.202.40]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id B7821400F27; Tue, 22 Mar 2016 13:25:29 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id B092C5BE; Tue, 22 Mar 2016 17:25:27 -0300 (CLT) Date: Tue, 22 Mar 2016 17:25:27 -0300 From: Alvaro Herrera To: ivan@adicional.com.br Cc: pgsql-bugs@postgresql.org Subject: Re: problem in sql - sum() Message-ID: <20160322202527.GA510502@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <206706195.1632677.1458657729534.JavaMail.zimbra@adicional.com.br> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -1.1 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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