DEV Community

Saiful Islam
Saiful Islam

Posted on

i can not covert this query

SELECT s1.product_id,s1.totalstock,s2.totalstock as assign,s3.totalstock as warrenty,s4.totalstock as damage,s5.totalstock as missing,s6.totalstock as returnProduct FROM stock_details as s

        left JOIN (SELECT sum(s.quantity) as totalstock,s.product_id FROM stock_details as s WHERE s.status_type=1 GROUP BY s.product_id) as s1 ON s1.product_id = s.product_id
        left JOIN (SELECT sum(s.quantity) as totalstock,s.product_id FROM stock_details as s WHERE s.status_type=2 GROUP BY s.product_id) as s2 ON s2.product_id = s.product_id
        left JOIN (SELECT sum(s.quantity) as totalstock,s.product_id FROM stock_details as s WHERE s.status_type=3 GROUP BY s.product_id) as s3 ON s3.product_id = s.product_id
        left JOIN (SELECT sum(s.quantity) as totalstock,s.product_id FROM stock_details as s WHERE s.status_type=4 GROUP BY s.product_id) as s4 ON s4.product_id = s.product_id
        left JOIN (SELECT sum(s.quantity) as totalstock,s.product_id FROM stock_details as s WHERE s.status_type=5 GROUP BY s.product_id) as s5 ON s5.product_id = s.product_id
        left JOIN (SELECT sum(s.quantity) as totalstock,s.product_id FROM stock_details as s WHERE s.status_type=6 GROUP BY s.product_id) as s6 ON s6.product_id = s.product_id

        GROUP BY s.product_id
Enter fullscreen mode Exit fullscreen mode

Top comments (0)