日期:2014-05-19  浏览次数:20714 次

一个表内统计查询
怎样实现这样的查询
表中有字段
id   date   name   money   4个字段  

id       date         name       money
1     2006-2-1     阿             10
2     2007-3-1     哦             10
3     2007-3-5     阿             10
4     2006-2-6     adf           10
5     2007-5-6     adf           10

要得到结果
  year       month       money  
  2006         2                 20    
  2007         3                 20
  2007         5                 10
怎样写SQL语句?

------解决方案--------------------
select year(date) [year],month(date) [year],sum(money) [money] from 表
group by year(date),month(date)

------解决方案--------------------
select year([date]) as [year],month([date]) as [month],sum(money) as money
from tablename
group by year([date]) ,month([date])