某公司面试的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
原文地址:https://www.cnblogs.com/qanholas/p/2943143.html