56,677
社区成员
发帖
与我相关
我的任务
分享
DROP TABLE IF EXISTS t_g;
CREATE TABLE t_g
(t_id BIGINT AUTO_INCREMENT,
t_userid VARCHAR(20) DEFAULT '' COMMENT '用户id',
t_je VARCHAR(20) DEFAULT '' COMMENT '交易金额',
t_date VARCHAR(20) DEFAULT '' COMMENT '交易时间',
PRIMARY KEY(t_id)
);
-- 创建索引
CREATE INDEX i_a ON t_g (t_userid,t_date);
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('A','20','20160701');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('A','10','20160702');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('A','15','20160703');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('A','15','20160704');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('A','20','20160705');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('A','50','20160706');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('A','20','20160707');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('A','20','20160708');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('B','40','20160701');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('B','20','20160702');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('B','15','20160703');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('B','15','20160704');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('C','20','20160701');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('C','50','20160702');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('C','20','20160703');
INSERT INTO t_g (t_userid,t_je,t_date) VALUES ('C','20','20160704');
select x.t_userid,MIN(x.t_date) from
(select a.t_userid,a.t_date,(select sum(t_je) from t_g where t_userid = a.t_userid and t_date <= a.t_date
)total from t_g a)x
where x.total/100 > 70 GROUP BY x.t_userid;