赞
踩
生成近8天的日期(now() 和“ interval '8 DAY' ” 可以修改成指定日期来生成)格式 yyyy-mm-dd
- select to_char(generate_series, 'yyyy-mm-dd') as time
- from generate_series(to_char(now() - interval '8 DAY', 'yyyy-mm-dd') :: date,
- to_char(now(), 'yyyy-mm-dd') :: date, '1 DAY')
生成近8年的日期(与上同理 )格式:yyyy
- select generate_series as time
- from generate_series(to_char(now(), 'yyyy') :: int - 8, to_char(now(), 'yyyy') :: int)
生成近8个月的日期(格式 :yyyy-mm)
- SELECT TO_CHAR(NOW(), 'YYYY-MM') as time
- union all
- SELECT TO_CHAR(NOW() - INTERVAL '1 MONTH', 'YYYY-MM') as orderTime
- union all
- SELECT TO_CHAR(NOW() - INTERVAL '2 MONTH', 'YYYY-MM') as orderTime
- union all
- SELECT TO_CHAR(NOW() - INTERVAL '3 MONTH', 'YYYY-MM') as orderTime
- union all
- SELECT TO_CHAR(NOW() - INTERVAL '4 MONTH', 'YYYY-MM') as orderTime
- union all
- SELECT TO_CHAR(NOW() - INTERVAL '5 MONTH', 'YYYY-MM') as orderTime
- union all
- SELECT TO_CHAR(NOW() - INTERVAL '6 MONTH', 'YYYY-MM') as orderTime
- union all
- SELECT TO_CHAR(NOW() - INTERVAL '7 MONTH', 'YYYY-MM') as orderTime
- union all
- SELECT TO_CHAR(NOW() - INTERVAL '8 MONTH', 'YYYY-MM') as orderTime
生成指定年月份(格式 :yyyy-mm)
- SELECT concat('2022-',lpad(generate_series :: text,2,'0')) as time
- from generate_series(1,12)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。