![]() | PERCENTILE Structure |
Namespace: sqx
[SerializableAttribute] public struct PERCENTILE : IBinarySerialize
DECLARE @Percentile float = 0.75 -- 75% ;WITH sample_data AS (SELECT X FROM (VALUES (7), (9), (15), (18), (33), (35), (37.5), (45)) AS T(X)) SELECT sqx.PERCENTILE(X,@Percentile,0) M0, sqx.PERCENTILE(X,@Percentile,1) M1 , sqx.PERCENTILE(X,@Percentile,2) M2, sqx.PERCENTILE(X,@Percentile,3) M3 FROM sample_data /* M0 M1 M2 M3 ------------ ------------ ------------ ------------ 35 36.25 35.625 36.875*/
/* Winsorize */ DECLARE @MinPercentile float = 0.05, @MaxPercentile float = 0.95 ;WITH sample_data AS (SELECT X FROM (VALUES (92), (19), (101), (58), (1053), (91), (26), (78), (10), (13), (-40), (101), (86), (85), (15), (89), (89), (28), (-5), (41)) AS T(X)) SELECT X, sqx.RowMax(MinValue, sqx.RowMin(MaxValue, X)) AS X_Winsorize FROM (SELECT sqx.PERCENTILE(X,@MinPercentile,2) MinValue, sqx.PERCENTILE(X,@MaxPercentile,2) MaxValue FROM sample_data) p , sample_data ORDER BY X_Winsorize