SQL : 求月平均值 , 求周平均值

## 基金净值:求月平均值 

select month(date1) as "月份"
, min(jz) as "月最小值"
, round(avg(jz),4) as "月平均值"
, max(jz) as "月最大值"
from jjjz
where dm='660008' and year(date1)='2018'
group by month(date1)
order by 1
;

## 基金净值:求周平均值

select week(date1) as "周数"
, min(jz) as "周最小值"
, round(avg(jz),4) as "周平均值"
, max(jz) as "周最大值"
from jjjz
where dm='660008' and year(date1)='2018'
group by week(date1)
order by 1
;

python 计算平均数

# 计算平均数
def average(alist):
    nsum = 0.0
    for i in range(len(alist)):
        nsum += alist[i]
    return round(nsum / len(alist), 4)

h2database:

select WEEK(PARSEDATETIME(date1,'yyyyMMdd')) as weeks
, min(jz) as "周最小值"
, round(avg(jz),4) as "周平均值"
, max(jz) as "周最大值"
from jjjz
where dm='660008' and year(date1)='2018'
group by WEEK(PARSEDATETIME(date1,'yyyyMMdd'))
order by 1
;
发布了106 篇原创文章 · 获赞 27 · 访问量 33万+

猜你喜欢

转载自blog.csdn.net/belldeep/article/details/84925436
今日推荐