Re: Formatting a month in query output

Поиск
Список
Период
Сортировка
От Alexander Borkowski
Тема Re: Formatting a month in query output
Дата
Msg-id 41F82962.8070908@abri.une.edu.au
обсуждение исходный текст
Ответ на Re: Formatting a month in query output  ("Rodolfo J. Paiz" <rpaiz@simpaticus.com>)
Ответы Re: Formatting a month in query output  ("Rodolfo J. Paiz" <rpaiz@simpaticus.com>)
Список pgsql-novice
 > flightlog=> select to_char(date,'Mon YYYY') as month, count(num) as num,
 > sum(hrs_total) as hours from flights group by month order by date asc;
 >
 > ERROR:  column "flights.date" must appear in the GROUP BY clause or be
 > used in an aggregate function

Try this:

select to_char(date,'Mon YYYY') as month, count(num) as num,
sum(hrs_total) as hours from flights group by date, month order by date asc;

 > Using "order by date"
 > gets me an error since the date column is not used in the query.

It is (for sorting). "date" is just not grouped and you can't do this,
which is what the above error message is all about: you have group it or
use an aggregate function (e.g. count, sum, ...) on it as you do for all
other columns in that query.

Cheers,

Alex

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: SQL and function reference?
Следующее
От: "Rodolfo J. Paiz"
Дата:
Сообщение: Re: Two copies of every mail!