Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id BDAFF9FC898; Tue, 5 Jun 2007 09:45:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 29206-06; Tue, 5 Jun 2007 09:45:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 4228B9FB394; Tue, 5 Jun 2007 09:39:31 -0300 (ADT) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 4D17076E33; Tue, 5 Jun 2007 13:39:30 +0100 (BST) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 3B4892740C5; Tue, 5 Jun 2007 13:40:21 +0100 (BST) Message-ID: <46655981.4050403@archonet.com> Date: Tue, 05 Jun 2007 13:39:29 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.0 (X11/20070326) MIME-Version: 1.0 To: Loredana Curugiu Cc: pgsql-novice@postgresql.org, pgsql-sql@postgresql.org Subject: Re: JOIN References: <1c23c8e70706050111i5ba672d6j78bd9afa4b786616@mail.gmail.com> <1c23c8e70706050426y12d567ban70ffdafb75808e0e@mail.gmail.com> <4665537A.2060601@archonet.com> <1c23c8e70706050518v19c56d21j873985125b930db@mail.gmail.com> In-Reply-To: <1c23c8e70706050518v19c56d21j873985125b930db@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/28 X-Sequence-Number: 28518 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