首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

按月分组统计有关问题

2012-05-04 
按月分组统计问题created_date 是 表 A 的一个日期字段,amount和quan是表A的金额跟数量字段,我想按月分组

按月分组统计问题
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) 

热点排行