I need to create a different column of total sales which is the total of the sales units till that row. As our sales unit will increase, the total sales will increase row by row. I have attached the image to get the clear idea.
Screenshot
I need to create a different column of total sales which is the total of the sales units till that row. As our sales unit will increase, the total sales will increase row by row. I have attached the image to get the clear idea.
Screenshot
You can use the following query, which adds up all the sales upto that rowId
and for the specific product.
select (select sum(ids)
from TBL_NAME T1
where T1.rowid <= TBL_NAME.rowid and PRODUCT=TBL_NAME.PRODUCT
) as TotalSales
from TBL_NAME;
Following answer is for Oracle DB, you can understand the query and easily convert it to the product you want.
One method is use to use of subquery with correlation
approach
select *,
(select sum(sales) from table where product = t.product and ? <= t.?) TotalSales
from table t
However, you would required ?
(i.e. rowid
or id
) column that could specify your column ordering.