Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH boobies AS (SELECT Rate, ntile(20) OVER(ORDER BY Rate) AS n, COUNT(*) OVER(ORDER BY rate) AS x FROM RateCalculatorLookups)
- --select * from boobies
- /*
- rate, n, x
- NULL 1 3
- NULL 1 3
- NULL 2 3
- 10 2 4
- 14 3 5
- 15 3 6
- 20 4 7
- 37 4 8
- 42 5 9
- 44 5 10
- 45 6 11
- 50 6 16
- 50 7 16
- 50 7 16
- 50 8 16
- 50 8 16
- 51 9 18
- 51 9 18
- 55 10 20
- 55 10 20
- 56 11 21
- 58 11 22
- 59 12 23
- 65 13 25
- 65 14 25
- 73 15 26
- 85 16 27
- 87 17 28
- 91 18 29
- 100 19 30
- 900 20 31*/
- SELECT avg(Rate) FROM boobies WHERE (x >= 20 AND n BETWEEN 2 AND 19) OR (x < 20 AND n BETWEEN 2 AND x-1)
- -- 52,8888888888889
Advertisement
Add Comment
Please, Sign In to add comment