Re: Screwy behavior with SUM and multiple joins to same

From: David Link <dvlink(at)yahoo(dot)com>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Screwy behavior with SUM and multiple joins to same
Date: 2002-08-28 13:25:58
Message-ID: 20020828132558.44641.qmail@web13509.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--- Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> wrote:
>
> Maybe something like:
> select sum(s1.units) as store_1
> , sum(s2.units) as store_2
> , sum(sAll.units) as store_All
> from sales s1
> , sales s2
> , (select prod, sum(units)
> from sales s
> where s.prod = 'A'
> and s.store in (1,2)
> group by s.prod) as sAll
> where s1.store=1 and s1.prod = 'A'
> and s2.store=2 and s2.prod = 'A'
> and s1.prod = sAll.prod
>
> That'll make the inner subselect give
> one row I think.
>

Yes, you are absolutely right: with the SUM() in the subselect to get
back only one row and that's what I have.

c/
, (select prod, sum(units)
/
, (select prod, sum(units) as units

__________________________________________________
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christoph Dalitz 2002-08-28 13:35:52 worried about PGPASSWORD drop
Previous Message chin 2002-08-28 11:38:56 Columns in views