zoukankan      html  css  js  c++  java
  • 计算累计收益

    计算累计收益,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;
  • 相关阅读:
    .Net Core 第三方工具包整理
    .Net Core 读取appsettings.json的配置
    .Net Core 常见问题整理
    .Net Core 学习资料
    LVM使用
    PIP本地源搭建
    sed命令使用
    Shell脚本
    SNAT端口转发配置
    Ubuntu软件包管理
  • 原文地址:https://www.cnblogs.com/iloverain/p/8857821.html
Copyright © 2011-2022 走看看