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


Donate : Link

Medium Blog : Link

Applications : Link


My SQL Query :

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;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s