构建一个sql查询,它在某些行字段上执行聚合函数并将它们转换为列

I am working on a time tracking project with php and mysql.My table Structure is like this:

+---------+------------+------------+----+----+----+----+----+----+----+
| user_id | project_id |    date    | d1 | d2 | d3 | d4 | d5 | d6 | d7 |
+---------+------------+------------+----+----+----+----+----+----+----+
|       1 |          2 | 2015-06-07 |  3 |  4 |  5 |  6 |  2 |  1 |  3 |
|       2 |          2 | 2015-06-14 |  3 |  4 |  5 |  6 |  2 |  1 |  3 |
|       1 |          1 | 2015-06-21 |  3 |  4 |  5 |  6 |  2 |  1 |  3 |
|       3 |          2 | 2015-06-28 |  3 |  4 |  5 |  6 |  2 |  1 |  3 |
|       2 |          3 | 2015-07-05 |  3 |  4 |  5 |  6 |  2 |  1 |  3 |
|       1 |          2 | 2015-07-12 |  3 |  4 |  5 |  6 |  2 |  1 |  3 |
|       2 |          4 | 2015-07-19 |  3 |  4 |  5 |  6 |  2 |  1 |  3 |
+---------+------------+------------+----+----+----+----+----+----+----+

Here Date field is always sunday. d1, d2,d3 are hours. I want to generate a report between two dates which gives output like this:

+---------+------------+-------+-------+-------+-------+-------+-------+-------+
| user_id | project_id | week1 | week2 | week3 | week4 | week5 | week6 | total |
+---------+------------+-------+-------+-------+-------+-------+-------+-------+
|       1 |          1 |     2 |     2 |     2 |     2 |     2 |     3 |    13 |
|       1 |          2 |     2 |     3 |     3 |     2 |     2 |     3 |    15 |
+---------+------------+-------+-------+-------+-------+-------+-------+-------+

here weeks are sum of 7days hours i.e.(d1+d2+d3+d4+d5+d6+d7). Week fields will vary depending on how many weeks are there between the date range. How do I build a MySQL query to achieve this result without writing much,or any, php?