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)
但我想知道如何在给定日期计算表中所有行数的同时做到这一点 - 这还需要计算之前添加的行数。
例如,每月添加 5 行:我希望结果如下所示:一个月内的 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;