Percentile aggregate for SQL Server 2008 R2
问题 I'm using SQL Server 2008 R2. I need to compute a percentile value per group, something like: SELECT id, PCTL(0.9, x) -- for the 90th percentile FROM my_table GROUP BY id ORDER BY id For example, given this DDL (fiddle) --- CREATE TABLE my_table (id INT, x REAL); INSERT INTO my_table VALUES (7, 0.164595), (5, 0.671311), (7, 0.0118385), (6, 0.704592), (3, 0.633521), (3, 0.337268), (0, 0.54739), (6, 0.312282), (0, 0.220618), (7, 0.214973), (6, 0.410768), (7, 0.151572), (7, 0.0639506), (5, 0