Comment detail

年間カレンダー (Nested Flatten)
365行(or 366行)をだらーっと出力しますが、年間のカレンダーには一応なっています。

+------------------------+
| date                   |
+------------------------+
| 2008/1/1 (Tuesday)     | 
| 2008/1/2 (Wednesday)   | 
| 2008/1/3 (Thursday)    | 
(略)
| 2008/12/29 (Monday)    | 
| 2008/12/30 (Tuesday)   | 
| 2008/12/31 (Wednesday) | 
+------------------------+
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
-- いつものように数字を用意しておく
DROP TABLE if exists num_chars;
CREATE TABLE num_chars(id int not null);
INSERT INTO num_chars VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9);
DROP TABLE if exists nums;
CREATE TABLE nums as (
  SELECT n1.id + (n2.id * 10) + (n3.id * 100) as id
    FROM num_chars n1, num_chars n2, num_chars n3);

-- 2008年を指定
SET @ycalendar = 2008;
SELECT date_format(makedate(@ycalendar, id), '%Y/%c/%e (%W)') as date
  FROM nums
 WHERE nums.id between 1 and (365 + day(last_day(concat(@ycalendar, '-2-1'))) - 28);

Index

Feed

Other

Link

Pathtraq

loading...