select trunc(ref_date,'Q') q_date -- 季度第一天 ,max(ref_date) max_date -- 季度最后一天(若没过完,就取截止到今天的天数) ,(datediff(max(ref_date),trunc(ref_date,'Q'))+1) sum_day --季度天数 from tableA group by trunc(ref_date,'Q')2.计算最近3天数据(动态)
select ref_date -- 日期 ,amount -- 金额 ,sum(amount) over(order by ref_date rows between 2 preceding and current row) amount_3 -- 当前行到前移2行之和 ,sum(amount) over(order by ref_date rows between 2 preceding and 2 following) amount_33 --当前行前后各移2行之和 ,sum(amount) over(order by ref_date rows between unbounded preceding and unbounded following) amount_all --从第一行累加到最后一行 from tableA group by ref_date,amount
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)