Re: count question

Поиск
Список
Период
Сортировка
От Craig Ringer
Тема Re: count question
Дата
Msg-id 47FC25DB.2090803@postnewspapers.com.au
обсуждение исходный текст
Ответ на count question  (novice <user.postgresql@gmail.com>)
Ответы Re: count question  (rdeleonp@gmail.com)
Список pgsql-sql
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'


eg:

SELECT   meter_id, no_of_bays, meter_id::text||'-'||i::text AS bay_id
FROM meter,    generate_series(1, (select max(no_of_bays) from meter)) as i
WHERE i <= no_of_bays;


--
Craig Ringer


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

Предыдущее
От: novice
Дата:
Сообщение: count question
Следующее
От: rdeleonp@gmail.com
Дата:
Сообщение: Re: count question