包含sqlpercentile的词条
本篇文章给大家谈谈sqlpercentile,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、SQL求在 95% percentile(置信区间)的数,用STDEV函数调试有误
- 2、如何编写一个SQL存储过程来计算百分比,计算的方法就想Excel中的percentile一样! 请会的大虾们帮帮忙,谢
- 3、求用sql或存储过程实现excel函数 percentile
SQL求在 95% percentile(置信区间)的数,用STDEV函数调试有误
--这是MSSQL的
--1.建表
Create Table [Table]
(
[Item] Varchar(10),
[Item description] Varchar(10),
[Weight] int
)
--2.插入数据
insert into [Table] values('y12','screw',23)
insert into [Table] values('y12','screw',24)
insert into [Table] values('y12','screw',4)
insert into [Table] values('y12345','barrel',30)
--3.查询结果(y12345只有一条记录是没磨宽有标准偏差)
Select
A.[Item],
A.[Item description],
B.[LOWLIMIT],
B.[UPLIMIT]
拦毁 From [Table] A
Inner Join
简游备(
Select
[Item],
[Item description],
Avg([Weight])+0.95*StDev([Weight]) As UPLIMIT,
Avg([Weight])-0.95*StDev([Weight]) As LOWLIMIT
From [TABLE]
GROUP BY [Item],[Item description]
) B On A.[Item]=B.[Item]
And A.[Item description]=B.[Item description]
WHERE A.[Weight] Between LOWLIMIT And UPLIMIT
[img]如何编写一个SQL存储过程来计算百分比,计算的方法就想Excel中的percentile一样! 请会的大虾们帮帮忙,谢
用方法吧团缓知,用哪败存储过程做什么?
CREATE OR REPLACE FUNCTION f_get_percent(fz NUMBER, fm NUMBER) RETURN VARCHAR2 IS
v_result VARCHAR2(4000);
BEGIN
IF nvl(fm, 0) 0 THEN
v_result := round(nvl(fz, 0) / fm, 4) * 100 || '%';
END IF;
RETURN(v_result);
END f_get_percent;
用法:塌消SELECT f_get_percent(1, 3) FROM dual;
结果:33.33%
求用sql或存储过程实现excel函数 percentile
create table tb(Class int,Salary int,Median decimal(10,2))
insert tb select 1,50,NULL
union all select 2,150,NULL
union all select 3,100,NULL
union all select 4,200,NULL
union all select 5,200,NULL
union all select 6,300,NULL
union all select 7,350,NULL
union all select 8,400,NULL
union all select 9,400,NULL
union all select 10,500,NULL
go
create function f_calc(
@K decimal(3,2),
@Class int
)returns decimal(10,2)
as
begin
declare @re decimal(10,2)
if @K between 0 and 1
begin
declare @array table(id int identity(1,1),value int)
insert @array select Salary
from tb
order by Salary
set @re=(1-((@@rowcount-1)*@K-ROUND((@@rowcount-1)*@K,0,-1)))
*(select value from @array where id=ROUND((@@rowcount-1)*@K,0,-1)+1)
+((@@rowcount-1)*@K-ROUND((@@rowcount-1)*@K,0,-1))
*(SELECT value from @array where id=ROUND((@@rowcount-1)*@K,0,-1)+2)
end
return(@re)
end
go
select dbo.f_calc(0.5,0) ,dbo.f_calc(0.75,0) from tb
go
drop table tb
drop function f_calc
关于sqlpercentile和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。