$sql = "SELECT b.Id, b.BranchName, (SELECT SUM(PlanQty) FROM planstock WHERE ProductCode = 'KT08J' AND BranchId= b.Id GROUP BY ProductCode) as KT08J, (SELECT SUM(PlanQty) FROM planstock WHERE ProductCode = 'KT08' AND BranchId = b.Id GROUP BY 'ProductCode') as KT08
, (SELECT SUM(PlanQty) FROM planstock WHERE ProductCode = 'KT09' AND BranchId = b.Id GROUP BY 'ProductCode') as KT09, (SELECT SUM(PlanQty) FROM planstock WHERE 'ProductCode' = 'KT11' AND BranchId = b.Id GROUP BY 'ProductCode') as KT11
, (SELECT SUM(PlanQty) FROM planstock WHERE ProductCode = 'KT12' AND BranchId = b.Id GROUP BY 'ProductCode') as KT12
FROM branchstock as b)";
error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 4
$sql = "SELECT b.Id, b.BranchName,
(SELECT SUM(PlanQty) FROM planstock WHERE ProductCode = 'KT08J' AND BranchId= b.Id GROUP BY ProductCode) as KT08J,
(SELECT SUM(PlanQty) FROM planstock WHERE ProductCode = 'KT08' AND BranchId = b.Id GROUP BY ProductCode) as KT08,
(SELECT SUM(PlanQty) FROM planstock WHERE ProductCode = 'KT09' AND BranchId = b.Id GROUP BY ProductCode) as KT09,
(SELECT SUM(PlanQty) FROM planstock WHERE 'ProductCode' = 'KT11' AND BranchId = b.Id GROUP BY ProductCode) as KT11,
(SELECT SUM(PlanQty) FROM planstock WHERE ProductCode = 'KT12' AND BranchId = b.Id GROUP BY ProductCode) as KT12
FROM branchstock b";