From: | rdeleonp(at)gmail(dot)com |
---|---|
To: | novice <user(dot)postgresql(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: count question |
Date: | 2008-04-09 03:34:22 |
Message-ID: | a55915760804082034sf3b224eodb618515d6f23494@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 4/8/08, Craig Ringer <craig(at)postnewspapers(dot)com(dot)au> wrote:
> novice wrote:
>
> > Is it possible to write a query to produce:
> >
> > meter_id | no_of_bays | bay_id
> > ----------+------------+-----------
> > 5397 | 2 | 5397-01
> > 5397 | 2 | 5397-02
> > 5409 | 3 | 5409-01
> > 5409 | 3 | 5409-02
> > 5409 | 3 | 5409-03
>
> Sure. One way, not necessarily a particularly clever or efficient way,
> is to do a join with:
>
> generate_series(1, (select max(no_of_bays) from meter)) as i
>
> and use a WHERE clause to select for `i <= no_of_bays'
You have a problem, and it's bad design.
A bad design leads to these types of kludges.
Consider re-engineering your schema.
In any case, good luck.
From | Date | Subject | |
---|---|---|---|
Next Message | Volkan YAZICI | 2008-04-09 05:37:50 | Re: count question |
Previous Message | Craig Ringer | 2008-04-09 02:11:39 | Re: count question |