I have 3 table as below…
tbl_user
[sql]
user_id | name | division
1 | Anthony | admin
2 | Jane | admin
3 | Rachel | admin
4 | Abby | account
5 | Anna | account
6 | Henry | IT
7 | Jackson | IT[/sql]
tbl_course
[sql]
course_id | course_name | start_date | end_date | days | hours
1 | ABC | 2012-01-02 | 2012-01-04 | 3 | 0
2 | DEF | 2012-01-12 | 2012-01-12 | 0 | 6
3 | Yii Training | 2012-03-12 | 2012-03-16 | 5 | 0[/sql]
tbl_attend_course
[sql]
course_id | user_id
1 | 1
1 | 2
1 | 5
1 | 6
2 | 2
2 | 3
2 | 4
2 | 5
2 | 6[/sql]
a user may attend no course or more, a course might attended by one or more users.
My question is I want to generate report of number of days and hours for all user from a particular division which attended courses from
a range of start and end date.
sampel report as below…
[sql]
division : admin
start_date : 2012-01-01
end_date : 2012-01-31
user_id | name | course_id | days | hours
1 | Anthony | 1 | 3 | 0
2 | Jane | 1 | 3 | 0
2 | Jane | 2 | 0 | 6
3 | Rachel | 2 | 0 | 6
division : account
start_date : 2012-01-01
end_date : 2012-01-31
user_id | name | course_id | days | hours
5 | Anna | 1 | 3 | 0
4 | Abby | 2 | 0 | 6
5 | Anna | 2 | 0 | 6
division : IT
start_date : 2012-01-01
end_date : 2012-01-31
user_id | name | course_id | days | hours
6 | Henry | 1 | 3 | 0
6 | Henry | 2 | 0 | 6
7 | Jackson | NULL | NULL | NULL[/sql]
… Please help …