Skip to content
Advertisement

SQL: Return top 1% of values using NTILE function

I have a database with two columns as shown below, ID and COUNT_OF_ACTIONS where I want to return the top 1% of values from the COUNT_OF_ACTIONS – below might not be the best example, but imagine COUNT_OF_ACTIONS going from 0 to 100, so the query should return: 99 and 100 since these counts are >= 99 (top 1% value)

I tried to use the NTILE method to get all the values greater than the 99% point but this did not work. Any suggestions would be appreciaed.

Advertisement

Answer

A few changes to your syntax. This works:

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement