Hi Team,
need help on building the query
Existing query with output:
DECLARE @TABLE TABLE
(PLANID VARCHAR(10),Measurekey VARCHAR(10),submeasurekey VARCHAR(10)
,source_mesurement_year VARCHAR(10),source_Reported_year VARCHAR(10),Percentile varchar(100),value decimal(28,10) )
INSERT INTO @TABLE
SELECT 'SC','CDC','EYEEXAM','2016','2017','10th_percentile','39.6600000000'
UNION ALL
SELECT 'SC','CDC','EYEEXAM','2016','2017','33th_Percentile','51.6900000000'
UNION ALL
SELECT 'SC','CDC','EYEEXAM','2016','2017','66th_percentile','60.3400000000'
UNION ALL
SELECT 'SC','CDC','EYEEXAM','2016','2017','90th_percentile','68.2100000000'
UNION ALL
SELECT 'SC','CDC','EYEEXAM','2016','2017','Above90th_percentile','1.0000000000'
SELECT * FROM @TABLE
PLANID | Measurekey | submeasurekey | source_mesurement_year | source_Reported_year | Percentile | value |
---|---|---|---|---|---|---|
SC | CDC | EYEEXAM | 2016 | 2017 | 10th_percentile | 39.6600000000 |
SC | CDC | EYEEXAM | 2016 | 2017 | 33th_Percentile | 51.6900000000 |
SC | CDC | EYEEXAM | 2016 | 2017 | 66th_percentile | 60.3400000000 |
SC | CDC | EYEEXAM | 2016 | 2017 | 90th_percentile | 68.2100000000 |
SC | CDC | EYEEXAM | 2016 | 2017 | Above90th_percentile | 1.0000000000 |
Expected output:
PLANID | Measurekey | submeasurekey | source_mesurement_year | source_Reported_year | Percentile | value | Min | Max | Rank |
---|---|---|---|---|---|---|---|---|---|
SC | CDC | EYEEXAM | 2016 | 2017 | 10th_percentile | 39.66 | 0 | 0.3966 | 1 |
SC | CDC | EYEEXAM | 2016 | 2017 | 33th_Percentile | 51.69 | 0.3967 | 0.5169 | 2 |
SC | CDC | EYEEXAM | 2016 | 2017 | 66th_percentile | 60.34 | 0.517 | 0.6034 | 3 |
SC | CDC | EYEEXAM | 2016 | 2017 | 90th_percentile | 68.21 | 0.6035 | 0.6821 | 4 |
SC | CDC | EYEEXAM | 2016 | 2017 | Above 90th_percentile | 1 | 0.6822 | 1 | 5 |