Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Period Result
- 1 Green
- 1 Blue
- 1 Blue
- 1 Red
- 1 Blue
- 1 Blue
- 1 Blue
- 2 Green
- 2 Green
- 2 Green
- 2 Blue
- 2 Red
- 2 Red
- Period Result Percentage
- 1 Blue 72%
- 1 Green 9%
- 1 Red 9%
- 2 Blue 17%
- 2 Green 50%
- 2 Red 33%
- SELECT t.Period, t.Result, ((COUNT(t.Result) / Cnt) * 100) Percentage
- FROM table t
- INNER JOIN (SELECT Period, COUNT(*) Cnt
- FROM table
- GROUP BY Period) period_cnt
- ON t.Period = period_cnt.Period
- GROUP BY t.Period, t.Result
- select period,
- result,
- (count(result) / total_period) * 100 as result_percent
- from (
- select period,
- result,
- count(*) over (partition by period) as total_period
- from periods
- ) as t
- group by period, total_period, result
- order by period, result;
Add Comment
Please, Sign In to add comment