Need help for my SQL query

后端 未结 3 614
情话喂你
情话喂你 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:25

    Maybe like this. try it....

    Select Emp.F_Name As A,
      Proj.Project_Name As B,
      Count(ATT.Act_ID) As C,
      sum( IIF( ATT.Status IN ( 'Closed', 'OnHold' ), 0, 1 )) as D,
      (Count(ATT.Act_ID) / sum( IIF( ATT.Status IN ( 'Closed', 'OnHold' ), 0, 1 ))) * 100 as E 
    From Employee_Table As Emp Inner Join
      (Product_Table As Prod Inner Join
      (ATT_Table As ATT Inner Join Project_Table As Proj On Proj.Project_ID=ATT.Project_ID) 
      On Prod.Product_ID=ATT.Product_ID) 
      On Emp.Emp_ID=ATT.Assigned_To_ID
    Group By Emp.F_Name,Proj.Project_Name
    
    0 讨论(0)
  • 2021-01-25 10:29
    SELECT 
          E1.F_Name AS A, 
          P1.Project_Name AS B, 
          Count(A1.Act_ID) AS C, 
          sum( IF( A1.Status IN ( 'Closed', 'OnHold' ), 0, 1 )) as D,
          (Count(A1.Act_ID) / sum( IIF( A1.Status IN ( 'Closed', 'OnHold' ), 0, 1 ))) * 100 as E
       FROM 
          ATT_Table A1
             JOIN Employee_Table E1
                ON A1.Assigned_To_ID = E1.Emp_ID
             JOIN Project_Table P1
                ON A1.Project_ID = P1.Project_ID
       GROUP BY 
          F_Name, Project_Name;
    
    0 讨论(0)
  • 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;
    
    0 讨论(0)
提交回复
热议问题