SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE recibo ( `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, `activation_date` DATETIME, `el_value` int(11) ); INSERT INTO recibo (id, activation_date, el_value) VALUES (1, '2020-01-15', 10 ), (2, '2020-02-13', 10 ), (3, '2020-02-15', 10 ), (4, '2020-03-01', 10 ), (5, '2020-03-03', 10 ), (6, '2020-05-01', 10 ), (7, '2020-06-01', 10 ), (8, '2020-07-15', 10 ), (9, '2020-08-15', 10 ), (10, '2020-08-15', 10 ), (11, '2020-08-19', 10 ); /* SELECT date_format(activation_date, '%Y-%m') as yearMonth, SUM(el_value) over (order by MONTH(activation_date) )as cumulative FROM recibo -- WHERE activation_date >= :start group by yearMonth ;*/ SELECT id, activation_date, date_format(activation_date, "%Y-%m") as anyoMes, el_value, SUM(el_value) OVER(ORDER BY activation_date) AS cumulative_sum FROM recibo ; select laUnion.anyoMes, max(laUnion.cumulative_sum) as acumulado from( SELECT id, activation_date, date_format(activation_date, "%Y-%m") as anyoMes, el_value, SUM(el_value) OVER(ORDER BY activation_date) AS cumulative_sum FROM recibo ) as laUnion group by laUnion.anyoMes -- group by anyoMes ;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear