pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #10405: Sum not working with left join
3+ messages / 3 participants
[nested] [flat]

* BUG #10405: Sum not working with left join
@ 2014-05-20 08:39 cousinka@gmail.com
  2014-05-20 17:57 ` Re: BUG #10405: Sum not working with left join John R Pierce <pierce@hogranch.com>
  2014-05-21 19:31 ` Re: BUG #10405: Sum not working with left join rodriguez <rodriguez@ort.edu.uy>
  0 siblings, 2 replies; 3+ messages in thread

From: cousinka@gmail.com @ 2014-05-20 08:39 UTC (permalink / raw)
  To: pgsql-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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #10405: Sum not working with left join
  2014-05-20 08:39 BUG #10405: Sum not working with left join cousinka@gmail.com
@ 2014-05-20 17:57 ` John R Pierce <pierce@hogranch.com>
  1 sibling, 0 replies; 3+ messages in thread

From: John R Pierce @ 2014-05-20 17:57 UTC (permalink / raw)
  To: pgsql-bugs

On 5/20/2014 1:39 AM, cousinka@gmail.com wrote:
> 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.

the bug report list is NOT a suitable forum for this 'how to' discussion.



-- 
john r pierce                                      37N 122W
somewhere on the middle of the left coast



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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #10405: Sum not working with left join
  2014-05-20 08:39 BUG #10405: Sum not working with left join cousinka@gmail.com
@ 2014-05-21 19:31 ` rodriguez <rodriguez@ort.edu.uy>
  1 sibling, 0 replies; 3+ messages in thread

From: rodriguez @ 2014-05-21 19:31 UTC (permalink / raw)
  To: pgsql-bugs

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2014-05-21 19:31 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-05-20 08:39 BUG #10405: Sum not working with left join cousinka@gmail.com
2014-05-20 17:57 ` John R Pierce <pierce@hogranch.com>
2014-05-21 19:31 ` rodriguez <rodriguez@ort.edu.uy>

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