create table #PERCENTILE_test
(
id int,
col1 dec(12,4)
)
insert into #PERCENTILE_test
select 1,12 union all
select 1,18 union all
select 1,23 union all
select 1,25 union all
select 1,36 union all
select 1,42 union all
select 1,67 union all
select 1,74 union all
select 1,80 union all
select 1,90 union all
select 1,114 union all
select 1,135 union all
select 1,144 union all
select 1,176
SELECT SUM(MIN_Data) AS MIN_Data
, SUM([percont0.1]) AS [percont0.1]
, SUM([percont0.25]) AS [percont0.25]
, SUM([percont0.5]) AS [percont0.5]
, SUM([percont0.75]) AS [percont0.75]
, SUM([percont0.9]) AS [percont0.9]
, MAX(Max_Data) AS Max_Data
FROM
( SELECT MIN(col1) AS MIN_Data
, 0 AS [percont0.1]
, 0 AS [percont0.25]
, 0 AS [percont0.5]
, 0 AS [percont0.75]
, 0 AS [percont0.9]
, MAX(col1) AS Max_Data
FROM #PERCENTILE_test (NOLOCK)
UNION ALL
SELECT DISTINCT 0 AS MIN_Data
, PERCENTILE_cont (0.1) WITHIN GROUP (ORDER BY col1) over(partition by id) as percont0_5
, PERCENTILE_cont (0.25) WITHIN GROUP (ORDER BY col1) over(partition by id) as percont0_5
, PERCENTILE_cont (0.5) WITHIN GROUP (ORDER BY col1) over(partition by id) as percont0_5
, PERCENTILE_cont (0.75) WITHIN GROUP (ORDER BY col1) over(partition by id) as percont0_5
, PERCENTILE_cont (0.9) WITHIN GROUP (ORDER BY col1) over(partition by id) as percont0_5
, 0 Max_Data
FROM #PERCENTILE_test (NOLOCK) ) T