Skip to main content
deleted 13 characters in body
Source Link

Finally as I did not see any hope I inserted a column of name of item "prodname" and with this sql I got the result. But any hephelp will be welcome wihout this change whichadd of prodname makes my TB_A table a little bulky.

Here is the SQL

SELECT sd.prodname, sd.date, 
SUM(IF((sd.status=0 AND (sd.prodid=pb.id OR sd.prod.id=pm.id OR sd.prodid =pg.id)), sd.qty,0)) AS tot,
SUM(IF((sd.status >0 AND (sd.prodid=pb.id OR sd.prodid=pm.id OR sd.prodid=pg.id)), sd.qty, 0)) AS rq
FROM TB_A AS sd
LEFT JOIN TB_B AS pb ON pb.id=sd.prodid
LEFT JOIN TB_C AS pm ON pm.id=sd.prodid
LEFT JOIN TB_D AS pg ON pg.id=sd.prodid
WHERE sd.stat>1
GROUP BY pm.id,pm.id,pg.id,sd.prodname  
ORDER BY sd.date DESC

PS:In my display of my program I don't display rq I display tot-rq within a program. Any suggestion for getting that in this query is welcome.

Finally as I did not see any hope I inserted a column of name of item "prodname" and with this sql I got the result. But any hep will be welcome wihout this change which makes my TB_A a little bulky.

Here is the SQL

SELECT sd.prodname, sd.date, 
SUM(IF((sd.status=0 AND (sd.prodid=pb.id OR sd.prod.id=pm.id OR sd.prodid =pg.id)), sd.qty,0)) AS tot,
SUM(IF((sd.status >0 AND (sd.prodid=pb.id OR sd.prodid=pm.id OR sd.prodid=pg.id)), sd.qty, 0)) AS rq
FROM TB_A AS sd
LEFT JOIN TB_B AS pb ON pb.id=sd.prodid
LEFT JOIN TB_C AS pm ON pm.id=sd.prodid
LEFT JOIN TB_D AS pg ON pg.id=sd.prodid
WHERE sd.stat>1
GROUP BY pm.id,pm.id,pg.id,sd.prodname  
ORDER BY sd.date DESC

PS:In my display of my program I don't display rq I display tot-rq within a program. Any suggestion for getting that in this query is welcome.

Finally as I did not see any hope I inserted a column "prodname" and with this sql I got the result. But any help will be welcome this add of prodname makes my TB_A table a little bulky.

Here is the SQL

SELECT sd.prodname, sd.date, 
SUM(IF((sd.status=0 AND (sd.prodid=pb.id OR sd.prod.id=pm.id OR sd.prodid =pg.id)), sd.qty,0)) AS tot,
SUM(IF((sd.status >0 AND (sd.prodid=pb.id OR sd.prodid=pm.id OR sd.prodid=pg.id)), sd.qty, 0)) AS rq
FROM TB_A AS sd
LEFT JOIN TB_B AS pb ON pb.id=sd.prodid
LEFT JOIN TB_C AS pm ON pm.id=sd.prodid
LEFT JOIN TB_D AS pg ON pg.id=sd.prodid
WHERE sd.stat>1
GROUP BY pm.id,pm.id,pg.id,sd.prodname  
ORDER BY sd.date DESC

PS:In my display of my program I don't display rq I display tot-rq within a program. Any suggestion for getting that in this query is welcome.

Source Link

Finally as I did not see any hope I inserted a column of name of item "prodname" and with this sql I got the result. But any hep will be welcome wihout this change which makes my TB_A a little bulky.

Here is the SQL

SELECT sd.prodname, sd.date, 
SUM(IF((sd.status=0 AND (sd.prodid=pb.id OR sd.prod.id=pm.id OR sd.prodid =pg.id)), sd.qty,0)) AS tot,
SUM(IF((sd.status >0 AND (sd.prodid=pb.id OR sd.prodid=pm.id OR sd.prodid=pg.id)), sd.qty, 0)) AS rq
FROM TB_A AS sd
LEFT JOIN TB_B AS pb ON pb.id=sd.prodid
LEFT JOIN TB_C AS pm ON pm.id=sd.prodid
LEFT JOIN TB_D AS pg ON pg.id=sd.prodid
WHERE sd.stat>1
GROUP BY pm.id,pm.id,pg.id,sd.prodname  
ORDER BY sd.date DESC

PS:In my display of my program I don't display rq I display tot-rq within a program. Any suggestion for getting that in this query is welcome.