How to Calculate Sum of Particular Column Based on Id in MySQL | Code Factory

select id, product_name as Product_Name, stock as Stock, sum(istock) as CF_Stock
from (
select *
from product_master t1,(
select t.id as iid, t.stock as istock, t.product_name as product
from product_master t
) t2
where t1.id >= t2.iid
order by t1.id, t1.product_name, t2.product
) t3
where product_name = product
group by id, product_name
order by product_name, id;

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

How to Use AWS Parameter Store

How To Deploy and Run Java APIs on AWS App Runner With CloudFormation

Tracing Java based Lambda using X-Ray and AWS PowerTools

Leading a world-class API experience