Re: Strange Problem

From: Jim Nasby <decibel(at)decibel(dot)org>
To: Gustavo Ces <g(dot)ces(at)pettra(dot)es>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Strange Problem
Date: 2007-07-13 15:35:09
Message-ID: C1997924-6336-429C-B9B6-F61A107532CB@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jul 9, 2007, at 9:22 AM, Gustavo Ces wrote:
> Hi all,
>
> I´ve got a strange problem, hope you could help. I´ve got a
> table (a ) with n tuples, and two fields , birthplace and birth
> date. There´s another table ( say b) with m tuples, where i´ve got
> a lot of polygons ( with their code, same as bithplace). Now i want
> to make a join, to obtain how many people corresponds to each place-
> polygon. I write
>
> create table personsbyplace as select a.birthplacecode as code,count
> (*) as peoplecount from a,b where
> a.birthplacecode=b.polygoncode group by birthplacecode
>
> Well, what i can´t understand is why "Select sum(count) from
> personsbyplace" is > than "a" row number! (n)
>
> In "b" i´ve got all places and "a" table is a list of people, with
> their place and birth date. It can´t be greater sum(count) than
> number of persons! Where is the mistake?

Probably because there's a duplicated polygonecode (might want to
stick some underscores in the field names so they're easier to read,
btw).

My question is: if you just want a count of people grouped by
birth_place_code, why join to b at all?
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jim Nasby 2007-07-13 15:39:29 Re: Fastest way to join materalized view to child tables
Previous Message Alvaro Herrera 2007-07-13 15:34:00 Re: Accent-insensitive search