I am writing this query:
with CTE as
(
SELECT testCategory, testType, compareTestCategory,A.MEDIAN, A.average from
tInputValue_SamplesRequired
)
Select testCategory,testType,C.Median,C.Average,C.Median + D.Median as change,C.Average + D.average as [%change],C.compareTestCat from CTE C
left outer CTE D
on C.testCategory = D.compareTestCategory
and C.testType = D.testType
I would like to get the recursive record such as below image :
However I the result I got is like below :
By right, if the compare test category is equal to test category, I would like to use the median and average to the calculation.