DefconDotNet

ntile truncated mean

Sep 26th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.45 KB | None | 0 0
  1.  
  2. /* AVG */
  3. -- AVG(Rate) OVER (PARTITION BY group_Id) AS AvgRate
  4. -- 2  89,9090909090909
  5. -- 3  58,3333333333333
  6.  
  7. /* NTILE */
  8. WITH truncatedSet AS (SELECT Rate, ntile(10) OVER(ORDER BY Rate) AS n FROM RateCalculatorLookups WHERE rate IS NOT NULL AND group_id = 3)
  9. SELECT * FROM truncatedSet
  10. -- 50   1   -- gets removed
  11. -- 50   2
  12. -- 50   3
  13. -- 50   4
  14. -- 50   5
  15. -- 100  6   -- should be removed
  16.  
  17. SELECT avg(Rate) FROM truncatedSet WHERE n BETWEEN 2 AND 19
  18. -- 60
Advertisement
Add Comment
Please, Sign In to add comment