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

  • 相关阅读:
    Thymeleaf 基本表达式
    html中<radio>单选按钮控件标签用法解析及如何设置默认选中
    <%@ page contentType="text/html; charset=utf-8" language="java"%>每一个字符的含义
    El表达式的关系运算符
    Centos7.6安装Docker安装
    linux必须熟练掌握的基础命令
    CentOS7.x编译安装zabbix4.0
    编译装php7.2 && nginx-1.14
    CentOS7.x安装MySQL5.7.25
    CentOS7.x安装kickstart
  • 原文地址:https://www.cnblogs.com/si812cn/p/1335748.html
Copyright © 2011-2022 走看看