1. 程式人生 > >DB2 取指定區間的自然天

DB2 取指定區間的自然天

自然日 DB2

oracle:

(Select to_char(a+1-Id,'YYYYMMDD') SHOW_TIME From (

SELECT rownum Id,to_date( #{endDate,jdbcType=VARCHAR} ,'YYYYMMDD') a FROM DUAL

CONNECT BY LEVEL <= to_date(#{endDate,jdbcType=VARCHAR},'YYYYMMDD') - to_date(#{startDate,jdbcType=VARCHAR},'YYYYMMDD') +1) Order By SHOW_TIME) d LEFT JOIN tableA


DB2:

--取指定區間的自然天

with date_list(SHOW_TIME) as

(select to_date(#{startDate,jdbcType=VARCHAR},'YYYYMMDD')

from test.tableA a where a.USER_ID=#{userId,jdbcType=VARCHAR}

union all

select date_list.SHOW_TIME+1 day

from test.tableA b ,date_list where b.USER_ID=#{userId,jdbcType=VARCHAR} and date_list.SHOW_TIME <= to_date( #{endDate,jdbcType=VARCHAR} ,'YYYYMMDD')),

--統計交易

trans_list(transDate,txnCount,txnAmt) as

(select .......)

--外連接獲取交易統計數據

select * from date_list d LEFT JOIN trans_list e


DB2 取指定區間的自然天