当前位置: 代码迷 >> Sql Server >> 按月分组统计有关问题
  详细解决方案

按月分组统计有关问题

热度:46   发布时间:2016-04-27 13:03:02.0
按月分组统计问题
created_date 是 表 A 的一个日期字段,amount和quan是表A的金额跟数量字段,我想按月分组统计金额跟数量(1\2\3\4等自然月统计),SQL怎么写?

------解决方案--------------------
SQL code
--按月求和select month(created_date)  as month,sum(amount),sum(quan)  from tb    group by month(created_date)
------解决方案--------------------
SQL code
--应该把年份也考虑进来吧,如果不用那么2楼就是对的了select year(created_date) as year,month(created_date)  as month,sum(amount),sum(quan)from tbgroup by year(created_date),month(created_date)
  相关解决方案