DefconDotNet

Untitled

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