Re: selecting random row

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: selecting random row
Дата
Msg-id 20020402174255.C4927@svana.org
обсуждение исходный текст
Ответ на selecting random row  (Heiko Klein <Heiko.Klein@met.no>)
Список pgsql-general
On Tue, Apr 02, 2002 at 06:57:21AM +0000, Heiko Klein wrote:
> Hi,
>
> out of a table i.e. people:
> id last first sex age address
>
> I would like to select a random id. Id's are a sequence, but some
> peoble have been deleted, so there are several id-holes in the
> table.
>
> Furthermore, I would like to specify the random person, like
>
> select 'random person id' from table where age > 60 and sex = 'm';

select * from table where age > 60 and sex = 'm' order by random() limit 1;

IIRC

HTH,
--
Martijn van Oosterhout <kleptog@svana.org>   http://svana.org/kleptog/
> Ignorance continues to thrive when intelligent people choose to do
> nothing.  Speaking out against censorship and ignorance is the imperative
> of all intelligent people.

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

Предыдущее
От: "Dominic J. Eidson"
Дата:
Сообщение: Re: Errors when running vacuumdb...
Следующее
От: Daniel Lundin
Дата:
Сообщение: Re: selecting random row