天天看點

面試之BI-SQL--table轉換[2]

month   salesPerMonth

1

2

3

4

5

6

寫條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]