From: rdeleonp@gmail.com
To: novice <user.postgresql@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: count question
Date: Tue, 8 Apr 2008 22:34:22 -0500
Message-ID: <a55915760804082034sf3b224eodb618515d6f23494@mail.gmail.com> (raw)
In-Reply-To: <47FC25DB.2090803@postnewspapers.com.au>
References: <ddcb1c340804081851y245f4776g9de74b5715e3a3e@mail.gmail.com>
<47FC25DB.2090803@postnewspapers.com.au>
On 4/8/08, Craig Ringer <craig@postnewspapers.com.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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: rdeleonp@gmail.com, user.postgresql@gmail.com
Subject: Re: count question
In-Reply-To: <a55915760804082034sf3b224eodb618515d6f23494@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox