I am Trying to Create cumulative column but unable to create it, please have look what i tried to calculate it.
mytable
create table mytable (
TotalQuantity Decimal(7)
);
insert into mytable (TotalQuantity) values
(0.0),
(0.0),
(1.0),
(0.0),
(2.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(0.0),
(1.0),
(1.0),
(0.0),
(1.0);
Based on above data set i wanted to calculate distinct wise count and cumulative sum
SELECT TotalQuantity AS DistinctTotalQuantity,
COUNT(TotalQuantity) AS COUNTVALUE,
@running_total := @running_total + COUNT(TotalQuantity) AS cumulative_sum
FROM mytable
JOIN (SELECT @running_total := 0) r
GROUP BY TotalQuantity