Best way to display number of overspent projects
I am using SQL Server 2012, but this, or something close, should work in MySQL:

USE Test;
GO
CREATE TABLE Departments
(
    Department NVARCHAR(255)
);
CREATE TABLE Projects
(
    Department NVARCHAR(255)
    , Project NVARCHAR(255)
    , MaxHours INT
);
CREATE TABLE Assignments
(
    Project NVARCHAR(255)
    , HoursWorked INT
);
GO
CREATE VIEW Budgets AS
    SELECT ProjectInfo.Department
        , COUNT(ProjectInfo.Project) AS NumberOfProjects
        , SUM(Projectinfo.OverBudget) AS NumberOfOverbudgetProjects
    FROM (
        SELECT D.Department
            , P.Project
            , P.MaxHours AS ProjectMaxHours
            , SUM(HoursWorked) AS TotalHoursWorked
            , CASE WHEN (SUM(HoursWorked) &gt; P.MaxHours) THEN 1 ElSE 0 END AS OverBudget
        FROM   Departments AS D
            INNER JOIN Projects AS P ON D.Department = P.Department 
            INNER JOIN Assignments AS A ON P.Project = A.Project
        GROUP BY D.Department
            , P.Project
            , P.MaxHours
        ) AS ProjectInfo
    GROUP BY ProjectInfo.Department;
GO
INSERT INTO Departments (Department) VALUES ('Marketing');
INSERT INTO Departments (Department) VALUES ('Sales');
INSERT INTO Projects (Department, Project, MaxHours) VALUES ('Marketing', 'MarketingProject1', 10);
INSERT INTO Projects (Department, Project, MaxHours) VALUES ('Marketing', 'MarketingProject2', 20);
INSERT INTO Projects (Department, Project, MaxHours) VALUES ('Sales', 'SalesProject1', 15);
INSERT INTO Projects (Department, Project, MaxHours) VALUES ('Sales', 'SalesProject2', 25);
INSERT INTO Assignments (Project, HoursWorked) VALUES ('MarketingProject1', 5);
INSERT INTO Assignments (Project, HoursWorked) VALUES ('MarketingProject1', 5);
INSERT INTO Assignments (Project, HoursWorked) VALUES ('MarketingProject1', 5);
INSERT INTO Assignments (Project, HoursWorked) VALUES ('MarketingProject2', 5);
INSERT INTO Assignments (Project, HoursWorked) VALUES ('MarketingProject2', 5);
INSERT INTO Assignments (Project, HoursWorked) VALUES ('SalesProject1', 14);
SELECT * FROM Budgets;


This returns the folloowing resultset, showing only the Marketing Department, which is over budget.