sql 数据计算问题。
有表MONEY
MONEY DATE
100 2012.1.1
1000 2012.1.2
200 2012.1.2
100 2012.2.2
200 2012.3.3
1000 2013.1.22
500 2013.2.1
1000 2013.2.18
200 2013.3.13
怎么样得出结果:
DATE
2012
2013
上面这个是跟据表得出存在的年份。
MONEY MONTH
1000 1
1500 2
200 3
这个是得出2013年每个月的合计。
------解决方案--------------------
select distinct year(DATE) from table
select sum(MONEY) as MONEY,month(MONTH) as MONTH
from table
where DATE>='2013-01-01' and Date<'2014-01-01'
group by month(MONTH)
------解决方案--------------------select distinct year(DATE) from table
select sum(MONEY) as MONEY,month(DATE) as MONTH
from table
where DATE>='2013-01-01' and Date<'2014-01-01'
group by month(DATE)