Re: efficient count/join query

Поиск
Список
Период
Сортировка
От Tomasz Myrta
Тема Re: efficient count/join query
Дата
Msg-id 3E43C503.6010508@klaster.net
обсуждение исходный текст
Ответ на efficient count/join query  (Gary Stainburn <gary.stainburn@ringways.co.uk>)
Список pgsql-sql
Gary Stainburn wrote:
> On Friday 07 Feb 2003 1:26 pm, Tomasz Myrta wrote:
> 
>>Gary Stainburn wrote:
>>
<cut>
> 
> Many appologoes Tomasz.
No problem
> 
> 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.
There were 2 bugs in this query:
- in group by - add field hcount
- counting when any roster doesn't exist for some history. Here is (I suppose) final query:

create view some_view as
selectcoalesce(hjid,rjid) as jid,coalesce(hsid,rsid) as sid,coalesce(hcount,0)+  sum(case when rjid is not null then 1
else0 end) as hcount
 
fromhistoryfull outer join roster on (hjid=rjid and hsid=rosid)
group by hjid,rjid,hsid,rosid,hcount;

Tomasz Myrta




В списке pgsql-sql по дате отправления:

Предыдущее
От: Gary Stainburn
Дата:
Сообщение: Re: efficient count/join query
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: which will be faster? w/ or w/o indices