Hi, I have a table A with one decimal-typed column Score. Now I want to create a view with A.Score and an additional bit-type column as follows:
1 - if the score is ranked as top 20% high score;
0 - otherwise.
I tried to create a view as: select A.score, IsTop20Perc(A.score) from A;
with IsTop20Perc as a function as follows:
Set @Return = cast(case when exists
(select top(20) percent with ties score from A order by score desc) a where score=@score
It works but it takes very long to execute the view. Is there a way to optimize it?
Any thoughts are appreciated. Thanks!
1 - if the score is ranked as top 20% high score;
0 - otherwise.
I tried to create a view as: select A.score, IsTop20Perc(A.score) from A;
with IsTop20Perc as a function as follows:
Set @Return = cast(case when exists
(select top(20) percent with ties score from A order by score desc) a where score=@score
It works but it takes very long to execute the view. Is there a way to optimize it?
Any thoughts are appreciated. Thanks!