SELECT TO_CHAR(ADD_MONTHS(ADD_MONTHS(sysdate, -24), ROWNUM - 1), 'YYYYMM') UNIT_DATE FROM DUAL CONNECT BY ROWNUM <= months_between(sysdate, ADD_MONTHS(sysdate, -24)) 替换成postgre
时间: 2023-05-26 12:05:15 浏览: 157
oracle中add_months()函数及用法总结
SELECT to_char(date_trunc('month', (CURRENT_DATE - interval '2 year')::timestamp) + (generate_series(0, date_part('year', age(CURRENT_DATE, (CURRENT_DATE - interval '2 year'))::interval) * 12 + date_part('month', age(CURRENT_DATE, (CURRENT_DATE - interval '2 year'))::interval)) * interval '1 month'), 'YYYYMM') AS UNIT_DATE FROM generate_series(0, date_part('year', age(CURRENT_DATE, (CURRENT_DATE - interval '2 year'))::interval) * 12 + date_part('month', age(CURRENT_DATE, (CURRENT_DATE - interval '2 year'))::interval)) AS t;
阅读全文