1

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?

davidahines
  • 3,816
  • 15
  • 50
  • 86

1 Answers1

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'

Reference

Community
  • 1
  • 1
Hyperboreus
  • 31,109
  • 9
  • 45
  • 84