Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help for my SQL query
    primarykey
    data
    text
    <p>Well I may have posted this earlier also, but unable to find the answer so far, so please help me on this one. </p> <p>My database structure: </p> <p><strong>ATT</strong> (<code>Activity</code> table)</p> <ul> <li>Act_ID(PK)</li> <li>Assigned_To_ID (FK, refer to <code>Emp_ID</code>)</li> <li>Project_ID (FK, refer to <code>Project_ID</code>)</li> <li>Product_ID (FK, refer to <code>Product_ID</code>)</li> <li>Status (can be <code>New, OnHold, Cancel, Closed</code>)</li> </ul> <p><strong>Product_Table</strong> </p> <ul> <li>Product_ID (PK)</li> <li>Product_Name</li> </ul> <p><strong>Project_Table</strong> </p> <ul> <li>Project_ID (PK)</li> <li>Project_Name</li> </ul> <p><strong>Employee_Table</strong> </p> <ul> <li>Emp_ID (PK)</li> <li>F_Name.</li> </ul> <p><strong>Constraints</strong> </p> <ul> <li>In 1 Project --> Multiple employees can work</li> <li>1 Employee -- > Can be assigned multiple activities (<code>Act_ID</code>)</li> <li>At any given point of time <code>Status</code> can be any of those given values</li> </ul> <p>Now in my SQL query what I want to do is a load check ::</p> <p>An activity (represented by <code>Act_ID</code>) is assigned to an employee is represented by <code>Assigned_To_ID</code>, for Project (<code>Project_ID</code> in <code>ATT_Table</code>) and a particular status. I need to output 5 values from my SQL query: </p> <ol> <li>Name of Employee</li> <li>Name of Project</li> <li>Number of total activities an Employee(In A) is assigned. </li> <li>Number of activities an Employee(In A) is assigned where Status is either New or InProcess.</li> <li>Load. That will be = C/D * 100 (C is a larger value than D, which is obvious.) </li> </ol> <p>Now There may be a condition That an employee let's say E1 is working on project P1,P2. So my table output will be look like this:: </p> <pre><code>A B C D E E1 P1 E1 P2 </code></pre> <p>So here C, D, E will be having values corresponding to activities for that Project(P1 or P2)</p> <p>I have tried this so far :: </p> <pre><code>SELECT F_Name AS A, Project_Name AS B, Count(Act_ID) AS C, Count(Act_ID) AS D FROM Employee_Table, ATT_Table, Project_Table WHERE ATT_table.[Assigned_To_ID] = Employee_Table.[Emp_ID] AND Project_Table.[Project_ID] = ATT_Table.[Project_ID] AND Count(Act_ID) IN (SELECT Count(Act_ID) FROM ATT_Table WHERE ATT_Table.[Status] &lt;&gt; 'Closed' AND ATT_Table.[Status] &lt;&gt; 'OnHold') GROUP BY F_Name, Project_Name; </code></pre> <p>I am getting A, B, C. But when I try to find the activities for status check I cannot execute this query as it gives me a message cannot write count in WHERE clause. please help me on this one. Thanks.. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload