!Modified!
I have a table (mySQL 5.0.x) which contains values for date ranges.
| id | link_id | type_id | value | start | end |
====================================================
| 1 | 1 | 1 | 10 | 201111 | 201202 |
| 2 | 1 | 2 | 20 | 201110 | 201201 |
| 3 | 1 | 1 | 100 | 201202 | 201202 |
| 4 | 2 | 1 | 40 | 201202 | 201203 |
where
- id is the id for record
- link_id is for linking the data to other tables
- type_id is for determining the type of the value from other table
- value is numerical value
- start and end define the range (real date or integer for year and month)
The trick is that I need to present total value per type and link for a given period on a monthly basis. So the result should be like this for the range 201201 - 201202:
| period | link_id | type_id | value |
======================================
| 201201 | 1 | 1 | 10 |
| 201202 | 1 | 1 | 110 |
| 201201 | 1 | 2 | 20 |
| 201201 | 2 | NULL | NULL |
| 201202 | 2 | 1 | 40 |
I could use PHP to put the information like this into the database but there are some drawbacks. I have hundreds of link_ids, many type_id, and the average difference between start and end dates is 30 months so I would have tons of rows.