Trying to group on date parts

Поиск
Список
Период
Сортировка
От Rob Anderson
Тема Trying to group on date parts
Дата
Msg-id FHEPJNONMOLHMPDJDOCMEEDAHIAA.roba@bml.uk.com
обсуждение исходный текст
Ответы Re: Trying to group on date parts  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
I am trying to select items from a file and to group on the CCYY-MM part of
the date, in order to give a total count of items for that period

SELECT
    SUBSTRING(mylog.datetime,1,7) AS datetime,
    count(*) as counter
FROM mylog
WHERE mylog.datetime<'2005-02-02'
GROUP BY SUBSTRING(mylog.datetime,1,7)
ORDER BY mylog.datetime;

However I get the error message

ERROR:  column "mylog.datetime" must appear in the GROUP BY clause or be
used in an aggregate function

I have also used date_trunc('month', mylog.datetime) with the same error

Help!!!!



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: VACUUM and other maintenance work
Следующее
От: "Keith Worthington"
Дата:
Сообщение: Calling trigger function from a function