表中有 三列 年,月,总数例如年 月 总数
2011 1 12
2009 3 14
2010 5 2
2011 6 22
2011 10 15
2010 12 3如何通过sql 将2011年9月之前的所有 总数 求和?
select sum(总数) from 表 where 年<2011 and 月<=9
上边的sql 是错的 这样的话 2010 12 的数据是取不到的。
2011 1 12
2009 3 14
2010 5 2
2011 6 22
2011 10 15
2010 12 3如何通过sql 将2011年9月之前的所有 总数 求和?
select sum(总数) from 表 where 年<2011 and 月<=9
上边的sql 是错的 这样的话 2010 12 的数据是取不到的。
select sum(总数) from 表 where 年<2011 and 月<=9将年月拼凑为正常日期格式select sum(总数) from
(select to_date(年||月,'yyyy-mm')as 日期, 总数 from 表)
where 日期<= 2011-09
(select to_date(年||月,'yyyy-mm')as 日期, 总数 from 表)
where 日期<= to_date(年||月,'2011-09')
where 年 < 2011 or (年=2011 and 月< 10)