Excel具有KURT函数,可返回数据集的峰度。 SQL Server是否具有等效的聚合函数?
答案 0 :(得分:1)
TSQL具有计算峰度所需的所有功能,但我认为你必须将它们全部放在自定义函数中。
这是我找到的一个实现(参考:SolidQ)
SELECT
Kurt = SUM(SQUARE(SQUARE(((Age*1.0-m.mean)/m.[StDev])))) * MIN(m.corrfact2) - MIN(m.subfact)
FROM
vTargetMail v
CROSS JOIN
(
SELECT
mean = AVG(Age*1.0), [StDev] = STDEV(Age),
corrfact2 = COUNT(*)*1.0 * (COUNT(*)+1) / (COUNT(*)-1) / (COUNT(*)-2) / (COUNT(*)-3),
subfact = 3.0 * SQUARE((COUNT(*)-1)) / (COUNT(*)-2) / (COUNT(*)-3)
FROM vTargetMail v
) AS m;
答案 1 :(得分:0)
我对此表示怀疑 - 这是一个模糊的功能,MySQL倾向于实现更接近数学基础核心的功能。
但是,Kurtosis计算自己是相当简单的。请参阅公式here。
答案 2 :(得分:0)
通过结合http://blogs.solidq.com/en/sqlserver/skewness-and-kurtosis-part-1-t-sql-solution/#abh_posts和https://sqlwithpanks.wordpress.com/2016/06/22/kurtosis-a-measure-of-tailedness-of-the-distribution/的方法,以下是经过测试的工作版本:
;with v as (select floor(rand(convert(varbinary,newid()))*365)+1 as X from dbo.TblModel07_High),
AGG as (SELECT m1 = AVG(X*1.0), sd1 = STDEV(X),corrfact1 = COUNT(*)*1.0 / (COUNT(*)-1) / (COUNT(*)-2),
[corrfact2] = COUNT(*)*1.0 * (COUNT(*)+1) / (COUNT(*)-1) / (COUNT(*)-2) / (COUNT(*)-3),
[subfact] = 3.0 * SQUARE((COUNT(*)-1)) / (COUNT(*)-2) / (COUNT(*)-3) from v)
SELECT N=count(*), Xmin=min(X), Xmax=max(X),M = MIN(m1),SD = MIN(sd1),CV = min(sd1)/min(m1),
Skew = SUM(((X*1.0 - m1)/sd1)*((X*1.0-m1)/sd1)*((X*1.0-m1)/sd1))* min(corrfact1),
Kurt = SUM( SQUARE( SQUARE( ( ( X * 1.0 - m1 )/sd1 ) ) ) ) * min(corrfact2) - min(subfact)+3 from v cross apply
(select m1,sd1,corrfact1,corrfact2,subfact from AGG) A