vous voudrez peut-être essayer quelque chose comme ce qui suit:
SELECT staff,
WEEK(date) week_no,
SUM(work_hours) as work_hours_sum
FROM log
GROUP BY staff, WEEK(date)
ORDER BY WEEK(date), staff;
cas de test (MySQL):
CREATE TABLE log (
uin int auto_increment primary key,
date date,
staff int,
work_hours int
);
INSERT INTO log (date, staff, work_hours) VALUES ('2010-06-01', 1, 5);
INSERT INTO log (date, staff, work_hours) VALUES ('2010-06-01', 2, 7);
INSERT INTO log (date, staff, work_hours) VALUES ('2010-06-02', 1, 2);
INSERT INTO log (date, staff, work_hours) VALUES ('2010-06-02', 2, 1);
INSERT INTO log (date, staff, work_hours) VALUES ('2010-06-08', 1, 2);
INSERT INTO log (date, staff, work_hours) VALUES ('2010-06-08', 2, 5);
INSERT INTO log (date, staff, work_hours) VALUES ('2010-06-09', 1, 6);
INSERT INTO log (date, staff, work_hours) VALUES ('2010-06-09', 2, 5);
Résultat:
+-------+---------+----------------+
| staff | week_no | work_hours_sum |
+-------+---------+----------------+
| 1 | 22 | 7 |
| 2 | 22 | 8 |
| 1 | 23 | 8 |
| 2 | 23 | 10 |
+-------+---------+----------------+
4 rows in set (0.00 sec)
thnx ... le second est celui que je cherchais ... – KoolKabin