前十条数据的分数字段的标准差 sql语句怎么写~~~~~~急

来源:百度知道 编辑:UC知道 时间:2024/06/20 22:42:34
查询前十条数据的分数字段的标准差 sql语句怎么写~~~~~~急

用StDevp方法就行,用的是wan_shan的表A,结果是0.5,如果选十条改成top(10)就行了
select StDevp(id) from (select top(2) id from A) as number

stdev函数

http://msdn.microsoft.com/zh-cn/library/ms155807.aspx

对系统的标准差算法有质疑,自己写了个算法,各位看看!
A表有两列id、number
id number
1 1
2 2
---------------------------------------------------
declare @m numeric(30, 20), @n int;
declare @i int, @x numeric(30, 20), @temp numeric(30, 20);
set @n=2;
set @i=0;
set @temp=0;
select @m=AVG(number) from A where id in (select top 2 id from A);
while (@i<2)
begin
if(@i=0)
begin
select @x=number from A where id = (select top 1 id from A where id not in (select top 0 id from A));
set @temp = @temp + power(@x-@m,2);
select @temp;
end
else if (@i=1)
begin
select @x=number from A where