I'm looking to make a date lookup table that will allow me to match some pivots together in excel and I was wondering how to go about taking the first of every week and adding it to a new mysql table?
Asked
Active
Viewed 57 times
1
-
First of week being being Monday or Sunday? Or what do you mean? – Hyperboreus Jul 07 '11 at 18:46
-
The first day of the week being Sunday. – davidahines Jul 07 '11 at 18:50
1 Answers
1
This query selects all sundays of 2011. Expand it for the years you need and insert this select into a table of your choice.
select a.Date
from (
select DATE('2011-12-31') - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date
from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) a
where DAYOFWEEK(a.Date)=1 and a.Date between '2011-01-01' and '2011-12-31'

Community
- 1
- 1

Hyperboreus
- 31,997
- 9
- 47
- 87