; WITH CTE AS
(
SELECT *, LAG(VALUE) OVER(ORDER BY MONTH) AS XX FROM YOURTABLE
)
SELECT AVG(CAST(VALUE AS FLOAT) / CAST(XX AS FLOAT)) FROM CTE WHERE XX IS NOT NULL
1
votes
Try this:
SELECT AVG(Calc)
FROM
(
SELECT t2.Value/t1.Value AS Calc
FROM [Table] t1
JOIN [Table] t2
ON t1.[Month] = t2.[Month] + 1
) calc
0
votes
Try Below Query .
select avg(CAST(a.value as FLOAT)/cast(a.mm as FLOAT)) from
(
SELECT *, LAG(value) OVER(ORDER BY MONTH) AS mm FROM #your_table
)
a where a.mm is not null
Please let us know if u have an concerns
0
votes
I want using query SQL for:
If i select month=3 => result = AVG(value2/value1,value3/value2)-1
If i select month=4 result = AVG(value2/value1,value3/value2,value4/value3)-1
Thanks
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more