Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WnCEc-0006wf-6T for pgsql-bugs@arkaria.postgresql.org; Wed, 21 May 2014 19:31:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WnCEb-00019C-1Q for pgsql-bugs@arkaria.postgresql.org; Wed, 21 May 2014 19:31:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1WnCEZ-000192-QQ for pgsql-bugs@postgresql.org; Wed, 21 May 2014 19:31:27 +0000 Received: from hermes.ort.edu.uy ([164.73.96.24]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WnCEW-0006eS-1d for pgsql-bugs@postgresql.org; Wed, 21 May 2014 19:31:26 +0000 Received: from hermes.ort.edu.uy (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 806591380A5 for ; Wed, 21 May 2014 16:31:20 -0300 (UYT) Received: from archie.ort.edu.uy (unknown [192.168.20.22]) by hermes.ort.edu.uy (Postfix) with ESMTP id 6690C1380A2 for ; Wed, 21 May 2014 16:31:20 -0300 (UYT) Received: from [172.30.10.6] (unknown [172.30.10.6]) by archie.ort.edu.uy (Postfix) with ESMTP id 61BCE1FA83 for ; Wed, 21 May 2014 16:31:20 -0300 (UYT) Message-ID: <537CFEFB.5070609@ort.edu.uy> Date: Wed, 21 May 2014 16:31:07 -0300 From: rodriguez User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: pgsql-bugs@postgresql.org Subject: Re: BUG #10405: Sum not working with left join References: <20140520083933.20343.8638@wrigleys.postgresql.org> In-Reply-To: <20140520083933.20343.8638@wrigleys.postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-MML: No X-TM-AS-Product-Ver: IMSVA-8.2.0.1679-7.5.0.1017-20708.001 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSVA-8.2.0.1679-7.5.1017-20708.001 X-TMASE-Result: 10--12.888400-5.000000 X-TMASE-MatchedRID: 4y9/ylYYqyaPvrMjLFD6eD6qwdnyD2fZzjEhISWZSrWqvcIF1TcLYD5S BjBCpgerVCYoAR6JGhGNRYlohjywSaOz+j0QSEPdbMGKOuLn5FXAMyYDvAr9ptq/PugZS7lhew1 Trvu1a7kjfxryBAc/EVpQaGNXo2NylgTSdHo6todPuMJi/ZAk8VtQw8FYzIROFRlN8zTSzj6YZ/ EdjXR3Oz7Iuem1C2RaV19r1eZ4vAVgVrply6HujU0IfQOJvRLR5Y0kb0hqatwzFWOYrWw6AySoq SYEcdZD0ayUDhqBG1dftuJwrFEhTbew1twePJJB2KDPNsqphTL6C0ePs7A07V9vMTaVNFNzrDw3 4aT0Dx/PUrqGxMRTFg7d/oJ3kqVFEtdVzCL7XYQ= X-Pg-Spam-Score: -2.6 (--) 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 El 20/05/2014 05:39 a.m., cousinka@gmail.com escribió: > The following bug has been logged on the website: > > Bug reference: 10405 > Logged by: Zoltan Jozsa > Email address: cousinka@gmail.com > PostgreSQL version: 9.1.12 > Operating system: Linux > Description: > > Hello. > I am a programmer from transylvania, i have a task where i have to get a > list of offer requests ordered by rate, but it's not working for me. > > I have written an SQL: > SELECT > OFREQD.offer_request_id, > OFREQD.offer_text, > OFREQD.offer_date,CD.company_name, ( sum( orr.rate ) ) AS offer_rating > > FROM offer_request_data AS OFREQD > JOIN offer_message_data AS OFMD ON ( OFREQD.offer_request_id = > OFMD.offer_request_id ) > JOIN company_data AS CD ON ( OFMD.recipient_company_id = CD.company_id ) > LEFT JOIN offer_request_rating orr ON orr.offer_request_id = > OFREQD.offer_request_id > > WHERE ( OFREQD.activity_id = 3239 OR OFMD.activity_id=3239 ) > AND OFREQD.is_checked = 1 > AND OFREQD.is_spam=0 > > GROUP BY OFREQD.offer_request_id,OFREQD.offer_text,CD.company_name > ORDER BY offer_rating DESC > > OFFSET 0 LIMIT 10 > > > > Please take a look on this SQL, and let me know if something is wrong in > SQL, or what can I do to do what the Client ask. > > If in the SELECT is SUM, then the server returns NULL as offer_rating for > every row, > if is COUNT then works fine. > > > Thank you, > Cousin! > > hi, all perhaps sum( coalesce(orr.rate,0) ), solves your problem -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs