I'm having trouble with getting the records for the following
TABLE
id | holiday_From | holiday_To
1 | 2012-01-02 | 2012-01-03
1 | 2012-01-11 | 2012-01-16
1 | 2012-01-08 | 2012-01-22
1 | 2012-01-29 | 2012-01-30
1 | 2012-01-08 | 2012-01-11
I'm trying to get occurrences of holidays for a given month - i.e.
BETWEEN "2012-01-01" AND "2012-01-31"
there is a similar post but im unable to tweak it for my needs
RESULT
day (within range) | count() //number of ppl on holiday
DATE | 3
for e.g.
SAMPLE OUTPUT
2012-01-02 | 1
2012-01-03 | 1
2012-01-08 | 2
2012-01-09 | 2
2012-01-10 | 2
2012-01-11 | 3
2012-01-12 | 2
2012-01-13 | 2
2012-01-14 | 2
2012-01-15 | 2
2012-01-16 | 2
......
In other words I am trying to get how many times a record is found for a specific date. I.e. how many people are on holiday on the 1st, 2nd 3nd etc.
Not every day is in the TABLE for each month
Any ideas?
p.s. this is what i have already (my shot in the dark)
SELECT h.holiday_From, h.holiday_To, COUNT( * )
FROM holiday h
JOIN holiday ho ON h.holiday_From
BETWEEN DATE( "2012-01-01" )
AND IF( DATE( "2012-01-31" ) , DATE( "2012-01-31" ) , DATE( "2012-01-01" ) )
GROUP BY h.holiday_From, h.holiday_To