Guest User

Untitled

a guest
Jan 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. Period Result
  2. 1 Green
  3. 1 Blue
  4. 1 Blue
  5. 1 Red
  6. 1 Blue
  7. 1 Blue
  8. 1 Blue
  9. 2 Green
  10. 2 Green
  11. 2 Green
  12. 2 Blue
  13. 2 Red
  14. 2 Red
  15.  
  16. Period Result Percentage
  17. 1 Blue 72%
  18. 1 Green 9%
  19. 1 Red 9%
  20. 2 Blue 17%
  21. 2 Green 50%
  22. 2 Red 33%
  23.  
  24. SELECT t.Period, t.Result, ((COUNT(t.Result) / Cnt) * 100) Percentage
  25. FROM table t
  26. INNER JOIN (SELECT Period, COUNT(*) Cnt
  27. FROM table
  28. GROUP BY Period) period_cnt
  29. ON t.Period = period_cnt.Period
  30. GROUP BY t.Period, t.Result
  31.  
  32. select period,
  33. result,
  34. (count(result) / total_period) * 100 as result_percent
  35. from (
  36. select period,
  37. result,
  38. count(*) over (partition by period) as total_period
  39. from periods
  40. ) as t
  41. group by period, total_period, result
  42. order by period, result;
Add Comment
Please, Sign In to add comment