guopengfa
发布于 2022-09-27 / 1462 阅读 / 0 评论 / 0 点赞

Some Corner SQL question

TABLE_A:

A	B
1	10
2	20
3	30
4	40
5	50

TABLE_B from TABLE_A":

A	B	C
1	10	10
2	20	30
3	30	60
4	40	100
5	50	150

C field: sum(B) who small or equal B

SQL detail:

select b.A, a.B, sum(b.B) sum_add
from test1.test1 a, test1.test1 b
where b.A >= a.A
group by b.A

so, it is so easy, right? 😂, Yeah, just use the same table, self to connect self, this is important. and remind the where condition. this cornor the examiner ask you very frequency.


评论