Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
単純に 2011 年 6 月に追加されたすべての行をカウントするのは非常に簡単です。
GROUP BY YEAR(record_date), MONTH(record_date)
しかし、特定の日付にテーブル内のすべての行の数を数えながらそれを行うにはどうすればよいのでしょうか。それには、以前に追加された行も数えなければなりません。
たとえば、1 か月あたり 5 行を追加します。結果を次のようにしたいと思います: 1 か月の間に 5、10、15 など。
SET @total = 0; SELECT Year, Month, new, @total := @total + new AS Total FROM ( SELECT YEAR(record_date) AS Year, MONTH(record_date) AS Month, COUNT(*) AS new FROM worktimes GROUP BY YEAR(record_date), MONTH(record_date) ) AS tmp;