sql語句建立日曆
http://www.itpub.net/thread-469543-1-1.html
2005年的帖子:
語句如下:
/* Formatted on 2010/06/20 15:13 (Formatter Plus v4.8.8) */
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 || '0101', 'yyyymmdd'), 'd') >
'1'
)
AND (TO_CHAR (dayofyear, 'd') <
TO_CHAR (TO_DATE (&year || '0101', 'yyyymmdd'),
'd'
)
)
THEN TO_CHAR (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 || '0101',
'yyyymmdd'
)
+ LEVEL
- 1 AS dayofyear
FROM DUAL
CONNECT BY LEVEL <=
TO_CHAR (TO_DATE (&year || '1231', 'yyyymmdd'),
'ddd'
)))
GROUP BY mon, mon_name, new_yweek
/
2005年的帖子:
語句如下:
/* Formatted on 2010/06/20 15:13 (Formatter Plus v4.8.8) */
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 || '0101', 'yyyymmdd'), 'd') >
'1'
)
AND (TO_CHAR (dayofyear, 'd') <
TO_CHAR (TO_DATE (&year || '0101', 'yyyymmdd'),
'd'
)
)
THEN TO_CHAR (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 || '0101',
'yyyymmdd'
)
+ LEVEL
- 1 AS dayofyear
FROM DUAL
CONNECT BY LEVEL <=
TO_CHAR (TO_DATE (&year || '1231', 'yyyymmdd'),
'ddd'
)))
GROUP BY mon, mon_name, new_yweek
/
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-665723/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 利用sql server直接建立日曆SQLServer
- sql語句建立表SQL
- 【SQL】日曆SQL
- SQL查詢日曆SQL
- 4.3.2 關於使用SQL語句建立CDBSQL
- Oracle用SQL列印日曆OracleSQL
- SQL語句收縮日誌檔案SQL
- 【Tips】使用SQL生成外來鍵的SQL建立語句SQL
- SQL語句SQL
- Java中如何解析SQL語句、格式化SQL語句、生成SQL語句?JavaSQL
- 常見的SQL語句(建立、刪除、切換)SQL
- SQL提取當前庫內索引的建立語句SQL索引
- 一條sql輸出本年日曆SQL
- sql語句大全SQL
- 共享SQL語句SQL
- SQL語句整理SQL
- SQL基本語句SQL
- 精妙Sql語句SQL
- SQL語句集合SQL
- oracle sql語句OracleSQL
- sql語句 求救!SQL
- SQL精妙語句SQL
- SQL語句收集SQL
- 常用SQL語句SQL
- sql常用語句SQL
- 【SQL】10 SQL UPDATE 語句SQL
- 【SQL】11 SQL DELETE 語句SQLdelete
- Oracle 建立序列語句Oracle
- 透過sql語句建立表時指定表空間的語法SQL
- Laravel 中輸出 SQL 語句的到 log 日誌LaravelSQL
- 透過java程式抽取日誌中的sql語句JavaSQL
- 通過java程式抽取日誌中的sql語句JavaSQL
- 【一句日曆】2024年11月
- 【SQLLDR】使用SQL*Loader輔助生成外部表建立語句SQL
- 【SQL】9 SQL INSERT INTO 語句SQL
- Java 周曆日曆Java
- 1.3. SQL 語句SQL
- Sql語句小整理SQL