mysql 查询每天每人累计求和问题
根据图一查询新加一列变成图二注意是mysql不能用with等Oracle操作我不会做啊求人帮忙!!!!!!!...
根据图一 查询新加一列 变成图二注意 是mysql 不能用with 等Oracle操作 我不会做啊 求人帮忙!!!!!!!
展开
展开全部
创建表:
create table test
(date datetime,
userid varchar(2),
amount int);
insert into test values ('2018-10-02 00:00:00','u1',20);
insert into test values ('2018-10-02 21:09:28','u2',20);
insert into test values ('2018-10-02 21:09:29','u3',30);
insert into test values ('2018-10-03 21:36:44','u1',20);
insert into test values ('2018-10-03 21:36:46','u2',72);
insert into test values ('2018-10-03 21:36:52','u3',30);
insert into test values ('2018-10-30 21:36:54','u1',10);
insert into test values ('2018-10-30 21:36:57','u2',10);
执行:
select a.date,a.userid,a.amount,sum(b.amount) from test a,test b where a.userid=b.userid and a.date>=b.date group by a.date,a.userid,a.amount
结果:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询