zoukankan      html  css  js  c++  java
  • sql 累积的计算方法

    Table1

    MntID  GroupID   SoldDate         Price        UpdateMonth

    1          1             2008/11/01    10          2008/11/01

    2          1             2008/11/05    25          2008/11/01

    3          2             2008/11/05    20          2008/11/01

    4          1             2008/11/07    15          2008/11/01

    5          2             2008/10/01    40          2008/10/01

    6          3            2008/09/28     20          2008/09/01

    7          1            2008/10/08     10          2008/10/01

    8          2            2008/09/11     20          2008/09/01

    求每个月的合计,并求出每个组的累加值:

    Select

     Q1.GroupID,Q1.UpdateMonth,SUM(Q1.Price) AS Price,SUM(Q2.Price) As TotalPrice

    From

    Select GroupID,UpdateMonth,SUM(Price) AS Price

    FROM

    Table1 

    GROUP BY GroupID,UpdateMonth

    ) AS Q1

    Inner join

    Select GroupID,UpdateMonth,SUM(Price) AS Price

    FROM

    Table1 

    GROUP BY GroupID,UpdateMonth

    AS Q2

    On

    Q2.GroupID = Q1.GroupID

    AND Q2.UpdateMonth < Q1.UpdateMonth

    Group BY Q1.GroupID,Q1.UpdateMonth

    Order BY Q1.GroupID,Q1.UpdateMonth

  • 相关阅读:
    ES6参考---Generator函数
    ES6参考---for...of方法
    ES6参考---Symbol属性
    ES6参考---形参默认值
    ES6参考---...运算符
    ES6参考---箭头函数
    legend3---一些手机浏览器打开网站提示安全证书有问题
    legend3---cdn加速oss域名配置问题
    一位草根炒房者的挣扎10年 竟落得如此下场
    LINUX:解压问题tar: Child returned status
  • 原文地址:https://www.cnblogs.com/si812cn/p/1335748.html
Copyright © 2011-2022 走看看