From: | Frank Bax <fbax(at)sympatico(dot)ca> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | simple? join |
Date: | 2002-01-04 17:10:00 |
Message-ID: | 3.0.6.32.20020104121000.00996cb0@pop6.sympatico.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
EMPLOYEE table contains: emp, first, last (emp is unique key)
TIMESHEET table contains: emp, timestamp, hours
I want to report employee name and total hours.
So far, I've come up with:
SELECT min(emp.first) as first, min(emp.last) as last, sum(ts.hours)
FROM timesheet ts, employee emp
WHERE ts.emp = emp.emp
GROUP by emp.emp
ORDER BY last, first;
It seems silly to specify "min" when I know there is only one value per emp!
SELECT first, last, sum(ts.hours)
FROM timesheet ts, employee emp
WHERE ts.emp = emp.emp
GROUP by emp.emp, first, last
ORDER BY last, first;
It seems silly to specify extraneous "group by" fields.
Is there a 'better' way to write this SQL?
Frank
From | Date | Subject | |
---|---|---|---|
Next Message | Bill Cunningham | 2002-01-04 19:20:30 | Re: Telling how many records are joined |
Previous Message | Andrew Perrin | 2002-01-04 16:29:37 | Telling how many records are joined |