Re: efficient count/join query

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: Tomasz Myrta <jasiek(at)klaster(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: efficient count/join query
Date: 2003-02-07 14:21:14
Message-ID: 200302071421.14672.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Friday 07 Feb 2003 1:26 pm, Tomasz Myrta wrote:
> Gary Stainburn wrote:
> > On Friday 07 Feb 2003 10:48 am, Tomasz Myrta wrote:
>
> <cut>
>
> > Hi Tomasz,
> >
[snip]
>
> I understood your problem well and I just thought some idea will be enough
> to continue work.
>
> Here is detailed query for your problem:
>
> create view some_view as
> select
> coalesce(hjid,rjid) as jid,
> coalesce(hsid,rsid) as sid,
> coalesce(hcount,1)+count(*)-1 as hcount
> from
> history
> full outer join roster on (hjid=rjid and hsid=rosid)
> group by hjid,rjid,hsid,rosid;
>
> Regards,
> Tomasz Myrta

Many appologoes Tomasz.

Because your select *LOOKED* wrong to me, I didn't even try it. Upon looking
at it again I can see what you're doing. When I tried, it complained about
the counts and grouping, so I moved the count(*) to a sub-select and changed
the coalesce and it's working.

Thanks,

Gary

>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

--
Gary Stainburn

This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tomasz Myrta 2003-02-07 14:38:59 Re: efficient count/join query
Previous Message jose antonio leo 2003-02-07 13:49:00 prosgrees + java + trasnacciones