I would like to select "extra" payments made in association with normal appointments for a one week period and SUM
them up by contractor
when calculating payroll
. Here's what I attempted:
SELECT SUM(extras.amount),
appointments.contractor_id
FROM extras
INNER JOIN appointments
ON extras.appt_id = appointments.appt_id
WHERE appointments.time > CURRENT_TIMESTAMP - interval '8 days'
AND appointments.time < CURRENT_TIMESTAMP
AND appointments.confirmed = 1
AND (appointments.status = 10 OR appointments.status = 12)
GROUP BY appointments.contractor_id;
I'd like to do this with just the one query, but I am getting this error from Postgres:
db=>
SELECT SUM(extras.amount), appointments.contractor_id from extras inner join appointments on extras.appt_id=appointments.appt_id;
ERROR: column "
appointments.contractor_id
" must appear in theGROUP BY
clause or be used in an aggregate functionLINE 1:
SELECT SUM(extras.amount), appointments.contractor_id from e...
I've tried playing around with the order of the clauses since I do have contractor_id
in the GROUP BY
statement.
What am I missing? Thanks for any suggestions.