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

  • 相关阅读:
    ElasticSearch实战:Linux日志对接Kibana
    想知道谁是你的最佳用户?基于Redis实现排行榜周期榜与最近N期榜
    详解CSS的Flex布局
    如何一步步在生产环境上部署django和vue
    Anisotropic Specular Shader
    Failed to install *.apk on device *: timeout
    logcat
    Android Debug Bridge
    DVI与VGA有什么区别
    Solo and Mute
  • 原文地址:https://www.cnblogs.com/si812cn/p/1335748.html
Copyright © 2011-2022 走看看