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
转载于:https://blog.51cto.com/1259519/2087475