Need help for my SQL query

后端 未结 3 649
情话喂你
情话喂你 2021-01-25 09:42

Well I may have posted this earlier also, but unable to find the answer so far, so please help me on this one.

My database structure:

ATT (

3条回答
  •  悲哀的现实
    2021-01-25 10:32

    You mentioned Product_Table, but I don't see how that table is involved in your question. For the rest, I would pull columns A, B, C, and D from a subquery, and compute E in the outer query.

    SELECT
        sub.F_Name AS A,
        sub.Project_Name AS B,
        sub.C,
        sub.D,
        ((sub.C / sub.D) * 100) AS E
    FROM
        (
            SELECT
                Emp.F_Name,
                Proj.Project_Name,
                Count(att.Act_ID) AS C,
                Sum(IIf(att.Status IN ('New', 'InProcess'), 1, 0)) AS D
            FROM
                (ATT_Table AS att
                INNER JOIN Employee_Table AS Emp
                ON Emp.Emp_ID = att.Assigned_To_ID)
                INNER JOIN Project_Table AS Proj
                ON Proj.Project_ID = att.Project_ID 
            GROUP BY
                Emp.F_Name,
                Proj.Project_Name
        ) AS sub;
    

提交回复
热议问题