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