Print calendar with an SQL statement

Source: Internet
Author: User
SELECT CASE
WHEN (new_yweek =
MIN (new_yweek) OVER (partition by mon order by new_yweek)
)
THEN mon_name
ELSE NULL
End as month,
New_yweek AS yweek,
ROW_NUMBER () OVER (partition by mon order by new_yweek) AS mweek,
SUM (DECODE (wday, '1', mday, NULL) AS sun,
SUM (DECODE (wday, '2', mday, NULL) AS mon,
SUM (DECODE (wday, '3', mday, NULL) AS tue,
SUM (DECODE (wday, '4', mday, NULL) AS wed,
SUM (DECODE (wday, '5', mday, NULL) AS thu,
SUM (DECODE (wday, '6', mday, NULL) AS fri,
SUM (DECODE (wday, '7', mday, NULL) AS sat
FROM (SELECT dayofyear AS everyday, TO_CHAR (dayofyear, 'mm') AS mon,
TO_CHAR (dayofyear, 'month') AS mon_name,
TO_CHAR (dayofyear, 'w') AS mweek,
TO_CHAR (dayofyear, 'ww ') AS yweek,
CASE
WHEN (TO_CHAR (TO_DATE (& year | '201312', 'yyyymmdd'), 'D')>
'1'
)
AND (TO_CHAR (dayofyear, 'D') <
TO_CHAR (TO_DATE (& year | '201312', 'yyyymmdd '),
'D'
)
)
THEN TO_CHAR (dayofyear, 'ww ') + 1, 'fm00 ')
ELSE TO_CHAR (dayofyear, 'ww ')
End as new_yweek,
TO_CHAR (dayofyear, 'D') AS wday,
TO_CHAR (dayofyear, 'dd') AS mday
FROM (SELECT TO_DATE (& year | '20140901 ',
'Yyyymmdd'
)
+ LEVEL
-1 AS dayofyear
FROM DUAL
Connect by level <=
TO_CHAR (TO_DATE (& year | '201312', 'yyyymmdd '),
'Ddd'
)))
Group by mon, mon_name, new_yweek;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.