Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wmo6i-0004Cg-0m for pgsql-bugs@arkaria.postgresql.org; Tue, 20 May 2014 17:45:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Wmo6h-0004jo-Al for pgsql-bugs@arkaria.postgresql.org; Tue, 20 May 2014 17:45:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wmfak-0007H3-AA for pgsql-bugs@postgresql.org; Tue, 20 May 2014 08:40:10 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Wmfad-0000OE-BE for pgsql-bugs@postgresql.org; Tue, 20 May 2014 08:40:10 +0000 MIME-Version: 1.0 Subject: BUG #10405: Sum not working with left join To: pgsql-bugs@postgresql.org From: cousinka@gmail.com Date: Tue, 20 May 2014 08:39:33 +0000 Message-ID: <20140520083933.20343.8638@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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! -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs