表test
id store
1 33
2 55
3 66
4 88
5 12
查询或的结果
id store store1 store2
1 33 33 33
2 55 88 121
3 66 154 275
4 88 242 517
5 12 254 771
求SQL语句
select id,store,store1,(select SUM(store1) from (select id,store,(select SUM(store) from t_test b where b.ID<=a.ID ) store1 from t_test a) copyt where copyt.ID<=thist.ID) store2 from (select id,store,(select SUM(store) from t_test b where b.ID<=a.ID ) store1 from t_test a) thist
如果是sqlserver和mysql用变量,如果是oracle用Lag
数据库里的数据是固定这些了吗,还是不固定这些的
表里就两列,查询的后变为四列,数据是不固定的
第三列我能求出来
select id,store,(select SUM(store) from test b where b.ID<=a.ID ) from test a
结果
id store store1
1 33 33
2 55 88
3 66 154
4 88 242
5 12 254
第四列我不知道怎么写了