Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. SELECT d.name, c.name as category_name,
  2. ROUND(
  3. (COUNT(r.id) / (SELECT COUNT(r.id) FROM reports as r
  4. JOIN categories as c ON r.category_id = c.id
  5. WHERE c.department_id = d.id)) * 100 /*get percentage here, then we round*/
  6. , 0) AS percentage FROM reports as r
  7. JOIN categories as c ON r.category_id = c.id
  8. JOIN departments as d ON c.department_id = d.id
  9. GROUP BY c.name
  10. ORDER BY d.name, c.name, percentage;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement