Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT d.name, c.name as category_name,
- ROUND(
- (COUNT(r.id) / (SELECT COUNT(r.id) FROM reports as r
- JOIN categories as c ON r.category_id = c.id
- WHERE c.department_id = d.id)) * 100 /*get percentage here, then we round*/
- , 0) AS percentage FROM reports as r
- JOIN categories as c ON r.category_id = c.id
- JOIN departments as d ON c.department_id = d.id
- GROUP BY c.name
- ORDER BY d.name, c.name, percentage;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement