I am doing a migration task, migrating a java application from Oracle Datastore to MySql 5.
You can imagine that some queries need to be rewritten. everything goes well until I came to Reporting module. Hope you guys could give me some hints.
Shortly I have a table: (say table name "Foo")
+-------------+-------------+
| | |
| d (datetime)| v (number) |
+-------------+-------------+
| 2000-01-01 | 3 |
| 2000-01-11 | 2 |
| 2002-07-01 | 1 |
+-------------+-------------+
What i have done so far:
when user gives startdate, enddate as parameters, i generate sum-report by Day and by month:
e.g. startDate 2000-01-01, endDate: 2003-01-01
+-------------+-------------+
| day | Sum |
+-------------+-------------+
| 2000-01-01 | 3 |
| 2000-01-11 | 2 |
| 2002-07-01 | 1 |
+-------------+-------------+
+-------------+-------------+
| Month | Sum |
+-------------+-------------+
| 2000-01 | 5 |
| 2002-07 | 1 |
+-------------+-------------+
but the requirement is, if the date is not in table, list the Day/month anyway, with sum=0. like:
+-------------+-------------+
| Month | Sum |
+-------------+-------------+
| 2000-01 | 5 |
| 2000-02 | 0 |
| 2000-03 | 0 |
| 2000-04 | 0 |
| 2000-05 | 0 |
| ... | ... |
| 2002-07 | 1 |
| ... | 0 |
+-------------+-------------+
This was achieved with Oracle, but I am stuck with Mysql. Can anyboy give some hints, better with example codes, how to achieve it with mySql?
thank you.