Re: JOIN

From: Richard Huxton <dev(at)archonet(dot)com>
To: Loredana Curugiu <loredana(dot)curugiu(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: JOIN
Date: 2007-06-05 12:39:29
Message-ID: 46655981.4050403@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql

Loredana Curugiu wrote:
>>> So I have the following query:>>
>
>> >> SELECT SUM(A.count),
>> >> A.theme,
>> >> A.receiver,
>> >> A.dates
>> >> FROM my_table A
>> >> INNER JOIN my_table B
>> >> ON A.theme=B.theme
>> >> AND A.receiver=B.receiver
>> >> AND A.date=ANY(B.dates)
>> >> GROUP BY A.theme,A.receiver, A.dates;
>> [snip]
>> >>
>> >> The result is wrong. I don't know what it is wrong at my query.
>> >> Please help.
>>
>> You don't actually say what's wrong. What are you expecting as output?
>
>
> I am trying to say that sum column it is not calculated correctly.

But you're not saying what you think the figure(s) should be.

There's two possibilities:
1. SUM() has a bug and can't add up numbers. Unlikely
2. The INNER JOIN isn't working as you think it should. This seems more
likely.

Try the query without totalling, just to see what matches you're getting.

> Oh, and your "date" column isn't - it's a timestamp with time-zone. That
>> might or might not cause confusion with daylight-saving-times.
>
>
> Yes, I am working with timestamp with time zone .

You're happy that daylight-saving adjustments aren't causing any
problems with your timezone settings then?

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Gregory Stark 2007-06-05 12:45:19 Re: JOIN
Previous Message Loredana Curugiu 2007-06-05 12:18:18 Re: [SQL] JOIN

Browse pgsql-sql by date

  From Date Subject
Next Message Gregory Stark 2007-06-05 12:45:19 Re: JOIN
Previous Message Loredana Curugiu 2007-06-05 12:18:18 Re: [SQL] JOIN