记录一则SQL面试题。。。
数据表test如图:要求统计截止到某月的总额。。。
sql:
方法1:
select t2.month,Sum(t1.amount) from test t1 inner join test t2 on t1.month<=t2.month group by t2.month
方法2:
select t1.month,(select sum(t2.amount) from test t2 where t2.month<=t1.month) from test t1
内容来自本人QQ空间日志发表于2010-12-2 00:21