pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: cousinka@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #10405: Sum not working with left join
Date: Tue, 20 May 2014 08:39:33 +0000
Message-ID: <20140520083933.20343.8638@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (3+ messages)  latest in thread

Message-ID: <20140520083933.20343.8638@wrigleys.postgresql.org>
Permalink:  ../20140520083933.20343.8638@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20140520083933.20343.8638@wrigleys.postgresql.org

 · 

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: cousinka@gmail.com
  Subject: Re: BUG #10405: Sum not working with left join
  In-Reply-To: <20140520083933.20343.8638@wrigleys.postgresql.org>
  References: <20140520083933.20343.8638@wrigleys.postgresql.org>

* 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