mysql 实现 每行累加
SELECT
DATE_FORMAT(bldat, '%Y-%m') AS month,
SUM(quantity) AS monthly_quantity,
SUM(quantity) OVER (ORDER BY DATE_FORMAT(bldat, '%Y-%m')) AS cumulative_quantity
FROM
sales
GROUP BY
DATE_FORMAT(bldat, '%Y-%m')
ORDER BY
month;
+---------+----------------+-------------------+ | month | monthly_quantity | cumulative_quantity | +---------+----------------+-------------------+ | 2023-01 | 15 | 15 | | 2023-02 | 11 | 26 | | 2023-03 | 22 | 48 | +---------+----------------+-------------------+

浙公网安备 33010602011771号