mysql running calculation reset by products

Viewed 13

Good day

I have gotten to a few examples on running totals and cumulative but i am stuck on doing calculations with a reset on product name.

Here is my code

AS you can see i am trying to get column 2/ column 1 *100, next one should be column 3 devided by the value of column 2/ column 1 *100 Column 4 then will be 4/ column 3 devided by the value of column 2/ column 1 *100

But it should start fresh after every product name change.

SELECT t.`DAY`,t.product,
       t.`rental_count`,
       @running_total:= (t.`rental_count`/@running_total) * 100 AS cumulative_sum
FROM
( SELECT
  `ipdate` AS DAY,`product`,
  `market_value_1` AS rental_count
  FROM `report_combined`
  GROUP BY `product`,`ipdate` ) t
JOIN (SELECT @running_total:=0) r
GROUP BY t.`product`,t.`DAY`
ORDER BY t.`product`,t.`DAY`;
0 Answers
Related