SQL Server的寫法:
<pre class="c" name="code">SELECT YEAR(DATEADD(MOHTH,-1,日期)) AS y, MONTH(DATEADD(MOHTH,-1,日期)) AS m
Oracle的寫法:
<pre class="c" name="code">SELECT YEAR(ADD_MONTHS(日期,-1)) AS y, MOHTH(ADD_MONTHS(日期,-1)) AS m
MySQL的寫法:
<pre class="c" name="code">SELECT YEAR(DATE_ADD(日期,INTERVAL -1 MONTH)) AS y,MONTH(DATE_ADD(日期,INTERVAL -1 MONTH)) AS m
補充新增SQL:
INSERT INTO ( cdate ) values (select TO_CHAR(ADD_MONTHS(sysdate,-1),'yyyymm') from dual )