Skip site navigation (1) Skip section navigation (2)

Re: join problem

From: Ragnar <gnari(at)hive(dot)is>
To: "A(dot) R(dot) Van Hook" <hook(at)lake-lotawana(dot)mo(dot)us>
Cc: postgresql sql list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: join problem
Date: 2007-06-21 18:43:00
Message-ID: 1182451380.5953.232.camel@localhost.localdomain (view raw or flat)
Thread:
Lists: pgsql-sql
On fim, 2007-06-21 at 08:46 -0500, A. R. Van Hook wrote:
> if I query for the total deposit using
>    select sum(deposit)
>    from invoice
>    where cusid = 2128"
> 
> I also get 1179.24, also the correct amount
> 
> 
> If I try an inclusive query using the following:
>      select
>       sum(i.rowtot + i.tax) as tot,
>       sum(v.deposit) as deposit
>     from cai c
>     join invoice           v on (v.cusid = c.cusid)
>     left join invoiceitems i on (v.ivid = i.ivid)
>     where v.cusid = 2128
>     group by 
>       c.cusid
> I get
>     tot    | deposit
> ----------+---------
>  1179.240 | 2819.24

you are adding the invoice deposit once for each item

gnari



In response to

Responses

pgsql-sql by date

Next:From: Fernando HeviaDate: 2007-06-21 22:00:45
Subject: Re: Constraint exclusion
Previous:From: Masaru SugawaraDate: 2007-06-21 16:29:00
Subject: Re: Subquery problems

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group