Mysql: Select all data between two dates -
I have a mysql table with data connected to the date, each row has data and a date, such as:
2009-06-25 75 2009-07-01 100 2009-07-02 120 I have a mysql query which can be used for all the data between two dates Selects. The question is:
Select data from Tbl Date between date and date 2 Date My problem is that I have a date 1 and date 2 Even if there is no data for the day.
So my query remembers those dates which are empty between 2009-06-25 and 2009-07-01.
Can I add these dates to data as just 0 in some way?
You can use a concept that is often referred to as the 'calendar table As a 'How to make Calendar tables in MySQL, there is a good guide to this:
- Create some basic features Create table entries (INTEGER); INtsER ints value (0), (1), (2), (3), (4), (5), (6), (7), (8), (9); - Works for only 100 days, join more entries and select more cal.date, tbl.data FROM (Select '2009-06-25' + INTERVAL ai * 10 + 2 days as a join date Ints b ORDER BY AI * 10 + 2) Leave Cal and do TLL on Cal Detet = TBL Date, where between '06 -06-2006 'and' 2009-07-01 'CLDAET; You may want to create a table cal instead of a subtext.
Comments
Post a Comment