Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- [Department Name],
- [Category Name],
- CAST(ROUND(CAST(Cnt AS DECIMAL(16,4))/CntMax*100,0) AS INT) AS Percentage
- FROM(
- SELECT d.Name AS [Department Name],
- c.Name AS [Category Name],
- COUNT(*) AS Cnt,
- (SELECT COUNT(*) FROM Reports AS r1 JOIN Categories
- AS c1 ON c1.Id = r1.CategoryId WHERE c1.DepartmentId=c.DepartmentId) AS CntMax
- FROM Reports AS r
- JOIN Categories AS c
- ON c.Id = r.CategoryId
- JOIN Departments AS d
- ON d.Id = c.DepartmentId
- GROUP BY c.DepartmentId,d.Name, c.Name
- ) T
- ORDER BY [Department Name],
- [Category Name],
- Percentage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement