sql怎么输出1-12月数据 并输出1-12月平均值数据?
2个回答
2020-01-06 · 百度认证:云南新华电脑职业培训学校官方账号
云南新华电脑学校
云南新华电脑学校是经云南省教育厅批准成立的省(部)级重点计算机专业学校,采用三元化管理模式,教学设备先进,师资雄厚学生毕业即就业,学院引进了电商企业入驻,创建心为电商创业园区,实现在校即创业
向TA提问
关注
展开全部
1.利用临时表补足数据(HANA)
select A.DATAYEAR as DATAYEAR, A.DATAMONTH as DATAMONTH,sum(DATANUM) as DATANUM from (select YEAR(GL_LZ_XKTZ_NY) as DATAYEAR,Month(GL_LZ_XKTZ_NY) as DATAMONTH,count(*) as DATANUMfrom TableNamewhere Year(GL_LZ_XKTZ_NY) >= year(ADD_YEARS(current_date,-1)) and Year(GL_LZ_XKTZ_NY) <= year(current_date)group by YEAR(GL_LZ_XKTZ_NY) , Month(GL_LZ_XKTZ_NY)
union select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 1 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 2 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 3 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 4 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 5 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 6 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 7 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 8 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 9 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 10 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 11 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 12 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(current_date) as DATAYEAR, 1 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(current_date) as DATAYEAR, 2 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(current_date) as DATAYEAR, 3 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(current_date) as DATAYEAR, 4 as DATAMONTH , 0 as DATANUM from DUMMY
select A.DATAYEAR as DATAYEAR, A.DATAMONTH as DATAMONTH,sum(DATANUM) as DATANUM from (select YEAR(GL_LZ_XKTZ_NY) as DATAYEAR,Month(GL_LZ_XKTZ_NY) as DATAMONTH,count(*) as DATANUMfrom TableNamewhere Year(GL_LZ_XKTZ_NY) >= year(ADD_YEARS(current_date,-1)) and Year(GL_LZ_XKTZ_NY) <= year(current_date)group by YEAR(GL_LZ_XKTZ_NY) , Month(GL_LZ_XKTZ_NY)
union select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 1 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 2 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 3 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 4 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 5 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 6 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 7 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 8 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 9 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 10 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 11 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(ADD_YEARS(current_date,-1)) as DATAYEAR, 12 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(current_date) as DATAYEAR, 1 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(current_date) as DATAYEAR, 2 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(current_date) as DATAYEAR, 3 as DATAMONTH , 0 as DATANUM from DUMMYunion select year(current_date) as DATAYEAR, 4 as DATAMONTH , 0 as DATANUM from DUMMY
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
查询所有数据然后将数据求平均
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询