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

  • 相关阅读:
    win10 下安装mysql8.0 zip
    CentOS7 安装mysql8
    linux 下 oracle 安装
    springboot restful jsonp 跨域请求
    Springboot mybatis generate 自动生成实体类和Mapper
    Spring MVC — @RequestMapping原理讲解二
    Spring MVC — @RequestMapping原理讲解一
    Android--LinearLayout中的属性baselineAligned的使用[转]
    Android--CountDownTimer倒计时工具类
    Android UI--SwipeDismissListView_直接删除
  • 原文地址:https://www.cnblogs.com/si812cn/p/1335748.html
Copyright © 2011-2022 走看看