MySQL 获取时间轴,跪求优化

在搭建数据仓库的过程中像时间,我们经常要获取各种形式的时间轴,oracle很强大我们轻易就可以获取,例如:
SELECT TRUNC(SYSDATE, 'MM') + ROWNUM - 1
  FROM DUAL
CONNECT BY ROWNUM <= TO_NUMBER(TO_CHAR(LAST_DAY(SYSDATE), 'dd'))

mysql中我目前只能这样做,希望达人优化下,顺便提升下我的SQL 能力
 
 
SELECT DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE())-1 DAY) ,INTERVAL a.idx DAY) FROM 
(SELECT 0 idx
UNION ALL
SELECT 1 idx
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
UNION ALL 
SELECT 10
UNION ALL 
SELECT 10
UNION ALL 
SELECT 11
UNION ALL 
SELECT 12
UNION ALL 
SELECT 13
UNION ALL 
SELECT 14
UNION ALL 
SELECT 15
UNION ALL 
SELECT 16
UNION ALL 
SELECT 17
UNION ALL 
SELECT 18
UNION ALL 
SELECT 19
UNION ALL 
SELECT 20
UNION ALL 
SELECT 21
UNION ALL 
SELECT 22
UNION ALL 
SELECT 23
UNION ALL 
SELECT 24
UNION ALL 
SELECT 25
UNION ALL 
SELECT 26
UNION ALL 
SELECT 27
UNION ALL 
SELECT 28
UNION ALL 
SELECT 29
UNION ALL 
SELECT 30) a  WHERE a.idx<DAY(LAST_DAY(CURDATE()))

 

你可能感兴趣的:(oracle,sql,优化,mysql,Date,数据仓库)