include("conn.php") ;
$sql1 = "SELECT sum((total_y) and `month` = '01') AS 'jan' , sum((total_y) and `month` = '02') AS 'feb' , sum((total_y) and `month` = '03') AS 'mar' , sum((total_y) and `month` = '04') AS 'apr' , sum((total_y) and `month` = '05') AS 'may' , sum((total_y) and `month` = '06') AS 'jun' , sum((total_y) and `month` = '07') AS 'jul' , sum((total_y) and `month` = '08') AS 'aug' , sum((total_y) and `month` = '09') AS 'sep' , sum((total_y) and `month` = '10') AS 'oct' , sum((total_y) and `month` = '11') AS 'nov' , sum((total_y) and `month` = '12') AS 'dec' , `year` FROM `form` WHERE dept_id='$dept_id' and year='$year' ";
$sqlquery1=mysql_db_query($dbname, $sql1);
SELECT CompanyName,QuantityPerUnit,
SUM(CASE WHEN UnitsInStock <= 0 THEN UnitsInStock ELSE 0 END) AS "Sum 0 ",
SUM(CASE WHEN 0 < UnitsInStock and UnitsInStock <= 5 THEN UnitsInStock ELSE 0 END) AS "Sum 1 to 5",
SUM(CASE WHEN 5 < UnitsInStock and UnitsInStock <= 10 THEN UnitsInStock ELSE 0 END) AS "Sum 6 to 10",
SUM(CASE WHEN 10 < UnitsInStock and UnitsInStock <= 15 THEN UnitsInStock ELSE 0 END) AS "Sum 11 to 15",
SUM(CASE WHEN 15 < UnitsInStock THEN UnitsInStock ELSE 0 END) AS "Sum 16+",
SUM(UnitsInStock) AS "Sum UnitsInStock",
SUM(1) as Total
FROM products p ,categories c ,suppliers s WHERE p.CategoryID = c.CategoryID and s.SupplierID= p.SupplierID
GROUP BY CompanyName,QuantityPerUnit