Select + min question

Поиск
Список
Период
Сортировка
От Devrim GUNDUZ
Тема Select + min question
Дата
Msg-id Pine.LNX.4.44.0206231435370.11727-100000@oper.metu.edu.tr
обсуждение исходный текст
Ответы Re: Select + min question  (Mathieu Arnold <mat@mat.cc>)
Список pgsql-sql
Hi,

I have created a table like this:

CREATE TABLE test (b_date char(8),active boolean,id serial
);

and inserted some rows.

Now,  what I want is to select the b_date which has the minimum "id" and 
active=t.

A normal query would be : SELECT b_date,min(id) FROM test WHERE active='t' GROUP BY id LIMIT 1

However, I only want to select b_date. So, if I perform the following 
query, I get the following error:

devrim=# SELECT b_date FROM test WHERE active='t' AND id=min(id) LIMIT 1;
ERROR:  Aggregates not allowed in WHERE clause

What should I do? ANy suggestions?

Best regards.
-- 

Devrim GUNDUZ

devrim@oper.metu.edu.tr
devrim.gunduz@linux.org.tr

Web : http://devrim.oper.metu.edu.tr
-------------------------------------






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

Предыдущее
От: Vernon Wu
Дата:
Сообщение: A problem on running a sql script in DBVisualizer
Следующее
От: "Christopher Kings-Lynne"
Дата:
Сообщение: Re: Select + min question