计算累计收益
计算累计收益,fund_account, init_date, total_income
drop table if exists data_stock; create table data_stock (account varchar(10),amount int,init_date varchar(20)); INSERT INTO `data_stock` VALUES ('2002', 210, '20170101'); INSERT INTO `data_stock` VALUES ('2001', 70, '20170101'); INSERT INTO `data_stock` VALUES ('2001', 200, '20170101'); INSERT INTO `data_stock` VALUES ('2001', 30, '20170103'); INSERT INTO `data_stock` VALUES ('2002', 10, '20170102'); SELECT * from data_stock; SELECT * from data_stock a LEFT JOIN data_stock b on a.account=b.account where a.init_date>=b.init_date group BY a.account,a.init_date; -- 关联条件 (可以算累计收益) SELECT a.account,a.init_date,sum(b.amount) as total from data_stock a left join data_stock b on a.account = b.account where a.init_date>=b.init_date group BY a.account,a.init_date;
本文版权归作者所有,转载请注明出处http://www.cnblogs.com/iloverain/.未经作者同意必须保留此段声明,否则保留追究法律责任的权利.