面试之BI-SQL--table转换[2]

时间:2021-09-12 17:58:48

month   salesPerMonth

1 2
2 3
3 2
4 4
5 3
6 3
                               

写条SQL语句把上表转成下表:

month   总销量

1             2

2             5

3             7

4             11

5             14

6             17

答案:

selects2.[month],Sum(s1.salesPerMonth)as'总销量'

FromSaless1,Saless2

where  s1.[month]<=s2.[month]

Groupbys2.[month]