Sql server 查找前9行的最小值和最大值
请告诉我如何使用excel中提供的公式计算E列。Sql server 查找前9行的最小值和最大值,sql-server,sql-server-2008,sql-update,Sql Server,Sql Server 2008,Sql Update,请告诉我如何使用excel中提供的公式计算E列。 可能有一种更有效的方法可以做到这一点,但这里有一种方法使用外部应用程序: @Mahdibm请在问题中具体说明。你能详细说明一下你想更新什么吗?将MaxT2.B+MinT2.C/2存储为我的table@MahdiIBM更新 select ROW_NUMBER() OVER (ORDER BY [A] asc) AS id,A,B,C,0 as E into #temp from dbo.rawdata order by id asc
可能有一种更有效的方法可以做到这一点,但这里有一种方法使用外部应用程序:
@Mahdibm请在问题中具体说明。你能详细说明一下你想更新什么吗?将MaxT2.B+MinT2.C/2存储为我的table@MahdiIBM更新
select ROW_NUMBER() OVER (ORDER BY [A] asc) AS id,A,B,C,0 as E into #temp from dbo.rawdata
order by id asc
-------------------------
update #temp
set E=((select max(h.B) from(select top (9) b.B from #temp b where b.id<#temp.id order by b.id asc)h) + (select min(l.C) from(select top (9) c.C from #temp c where c.id<#temp.id order by id asc)l))/2
where id>10
;With Cte As
(
Select *,
Row_Number() Over (Order By A) As RN
From YourTable
)
Select T1.A, T1.B, T1.C, T1.D, X.E
From Cte T1
Outer Apply
(
Select (Max(T2.B) + Min(T2.C)) / 2 As E
From Cte T2
Where T2.RN >= (T1.RN - 9)
And T2.RN < T1.RN
And T1.RN >= 10
) X
;With Cte As
(
Select *,
Row_Number() Over (Order By A) As RN
From YourTable
)
Update T1
Set E = X.E
From Cte T1
Outer Apply
(
Select (Max(T2.B) + Min(T2.C)) / 2 As E
From Cte T2
Where T2.RN >= (T1.RN - 9)
And T2.RN < T1.RN
And T1.RN >= 10
) X