
Explanation:

Comprehensive Detailed Explanation
We are tasked with writing a T-SQL query to denormalize the tables Employee and Contract in a Fabric warehouse.
Requirements Breakdown
Include attributes from matching rows in the Contract table
This means we must join Employee and Contract on EmployeeID .
Ensure that all rows from the Employee table are preserved
This requires a LEFT OUTER JOIN from Employee to Contract. If an employee has no contract, we still want the employee record included.
Return the total number of employees per contract type for all contract types that have more than two employees This means we need to:
Group by ContractType
Count distinct EmployeeID
Filter groups where that count > 2.
To filter aggregated results, we use HAVING , not WHERE.
Completed Query
WITH result AS (
SELECT
e.EmployeeID,
e.EmployeeName,
e.EmployeePosition,
c.ContractType,
c.StartDate
FROM Employee AS e
LEFT OUTER JOIN Contract AS c
ON c.EmployeeID = e.EmployeeID
)
SELECT
ContractType,
COUNT ( DISTINCT EmployeeID) AS TotalEmployees
FROM result
GROUP BY ContractType
HAVING COUNT ( DISTINCT EmployeeID) > 2 ;
Why This is Correct
LEFT OUTER JOIN ensures all employees are included, regardless of contracts.
HAVING allows filtering aggregated groups by employee counts.
The query returns ContractType , StartDate (as requested in denormalization), and aggregated employee counts.
References
T-SQL JOINs in Microsoft Fabric
Aggregate functions and HAVING clause
Denormalization best practices in Fabric warehouses