Re: sql select query with column 'AS' assignment

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: sql select query with column 'AS' assignment
Дата
Msg-id 12208.1012593670@sss.pgh.pa.us
обсуждение исходный текст
Ответ на sql select query with column 'AS' assignment  (DzZero <spinzero@aero-graphics.com>)
Список pgsql-hackers
DzZero <spinzero@aero-graphics.com> writes:
> agi_timesheets=# select distinct 
> employee_id,first_name,last_name,date,sum(hours),"R" as job_code from 
> timesheet group by employee_id,first_name,last_name,date having job_code 
> <> 'H' and job_code <> 'V' and date >= '01-01-2002' and date <= 
> '01-15-2002';
> ERROR:  Attribute 'R' not found

"R" and 'R' are two quite different things: "R" is a name, 'R' is a
literal constant.  Not sure how many of your problems stem from lack
of understanding of this basic point, but quite a few of them do.

> agi_timesheets=# select distinct 
> employee_id,first_name,last_name,date,sum(hours),job_code AS "R" from 
> timesheet group by employee_id,first_name,last_name,date having job_code 
> <> 'H' and job_code <> 'V' and date >= '01-01-2002' and date <= 
> '01-15-2002';
> ERROR:  Attribute timesheet.job_code must be GROUPed or used in an 
> aggregate function

Isn't the error message clear enough?  You need to add job_code to
the GROUP BY list.
        regards, tom lane


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: PostgreSQL crashes with Qmail-SQL
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: PostgreSQL crashes with Qmail-SQL