- Products -


Software


NEWS


Special



- Knowledge -


Category × Tag



- Like -

公開
作成日:2022/7/6
更新日:2022/7/6

SQLで年計を求める方法

・年計や何か月ごとの合算推移等はSQLで簡単に求められる。
・方法は、ウインドウ関数を使って、今のレコードの何個前までを対象として合算するかを指定するだけ。

使い方


・SQLの内容

select 列名指定
  , sum (計算対象の列名) over (
    order by 年月等並び替えに使う列名
    rows between 何個前までを対象とするか指定 preceding and current row) as 年計の列名
from
  テーブル名;


・具体例

select 年月
  , sum (売上) over (
    order by 年月
    rows between 11 preceding and current row) as 売上年計
from
  売上テーブル;


参考


https://qiita.com/omokawa_yasu/items/abb8624fc57a9f4c427c


Category



Tag




関連記事


{{tmp.name}}

{{article.category}} {{article.title}}