我正在寻找一个日期查找表,这将允许我在excel中匹配一些枢轴,我想知道如何去每周的第一个并将其添加到新的mysql表中?
答案 0 :(得分:1)
此查询选择2011年的所有星期日。在您需要的年份展开它,并将此选择插入您选择的表中。
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'