Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show the total number of employees and participants, and participation percentage in all departments?
    primarykey
    data
    text
    <p>I have the following database design:</p> <pre><code>Employees Table: EmployeeID, Name, OrgCode Departments Table: OrgCode, DepartName CompleteSurvey Table: ID, ParticipantID </code></pre> <p>And I need to develop one query that will display a table that shows the total number of employees in all departments and the total number of participants who completed the survey in all departments.</p> <p>I could be able to find the total number of employees in all department by the following query:</p> <pre><code>SELECT COUNT(DISTINCT dbo.Employees.EmployeeID) AS [Total Number of Employees] FROM dbo.Departments INNER JOIN dbo.Employees ON dbo.Departments.OrgCode = dbo.Employees.OrgCode CROSS JOIN dbo.CompleteSurvey </code></pre> <p>Then, I could be able to find the total number of participants in all department by the following query:</p> <pre><code>SELECT COUNT(DISTINCT dbo.CompleteSurvey.ID) AS [Total Number of Participants] FROM dbo.Departments INNER JOIN dbo.Employees ON dbo.Departments.OrgCode = dbo.Employees.OrgCode INNER JOIN dbo.CompleteSurvey ON dbo.Employees.EmployeeID = dbo.CompleteSurvey.RespondantID </code></pre> <p>But I should have a one query only.</p> <p>For example, if Department A has 100 employee and the number of participants is 50 out of 100 and Department B has 80 employee and the number of participants is 30</p> <p>The query should show the following:</p> <p><strong>the total number of employees in all departments = 180</strong></p> <p><strong>the total number of participants in all departments = 80</strong></p> <p><strong>the percent completion in all of them = 80/180 = 44%</strong></p> <p><strong>So how to do that?</strong></p>
    singulars
    1. This table or related slice is empty.
    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