如何在SQLServer2008中获取百分位数据
我在做一些数据分析。我只是个初学者。请帮我解决这个问题 我有一个下表,其中我想得到某一天如何在SQLServer2008中获取百分位数据,sql,sql-server,sql-server-2008,sql-server-2012,Sql,Sql Server,Sql Server 2008,Sql Server 2012,我在做一些数据分析。我只是个初学者。请帮我解决这个问题 我有一个下表,其中我想得到某一天持续时间毫秒数的90% RowId Depth StartMilliseconds DurationMilliseconds TxnDate 9869 3 169.8 80056.7 Jan 19 2015 9997 3 53 17593.8
持续时间毫秒数的90%
RowId Depth StartMilliseconds DurationMilliseconds TxnDate
9869 3 169.8 80056.7 Jan 19 2015
9997 3 53 17593.8 Jan 19 2015
10069 3 64.9 63072 Jan 19 2015
10950 4 67983.2 2198.9 Jan 20 2015
11178 5 2095.7 1886.5 Jan 20 2015
11490 3 16.4 818.4 Jan 20 2015
11751 5 36 1955.9 Jan 20 2015
11924 5 2078.9 2550.7 Jan 20 2015
11998 4 33.4 2071.4 Jan 20 2015
12283 3 12 1241.5 Jan 20 2015
12709 5 53 1480.9 Jan 21 2015
12827 3 14.8 501.6 Jan 21 2015
13193 5 2667.4 1604.7 Jan 21 2015
13315 4 43.1 1646.5 Jan 21 2015
13981 4 90 490.6 Jan 21 2015
14050 3 53.2 494 Jan 21 2015
14111 4 49 1464.8 Jan 21 2015
14253 4 32 1576.8 Jan 22 2015
14397 3 29.9 484.7 Jan 22 2015
14681 5 57.6 1522.6 Jan 22 2015
14779 4 45.8 1450.7 Jan 22 2015
我想要的输出是
Jan 19 2015 90% of DurationMiliseconds?
Jan 20 2015 90% of DurationMiliseconds?
Jan 21 2015 90% of DurationMiliseconds?
Jan 22 2015 90% of DurationMiliseconds?
有人能为我推荐同样的SQL查询吗?这就是您需要的吗
SELECT TxnDate, SUM(DurationMS) AS DurationMS, SUM(DurationMS) * 0.9 AS DurationMS90
FROM [table]
GROUP BY TxnDate
将输出,其中最后一列是第二列的90%
2015-01-19 160722.5 144650.25
2015-01-20 12723.3 11450.97
2015-01-21 7683.1 6914.79
2015-01-22 5034.8 4531.32
假设您希望输出90%的DurationMillimess列值,可以执行以下操作。您可以根据需要修改CAST
以设置小数位数的格式
GO
DECLARE @DurationMilliseconds AS DECIMAL(19,2) = 80056.7
SELECT CAST(@DurationMilliseconds * 0.9 As Decimal(19,2)) [DurationMilliseconds ]
-- Other way, its same as above but more readable.
SELECT CAST(@DurationMilliseconds * (90.0/100) As Decimal(19,2)) [DurationMilliseconds]
因此,您需要执行以下操作:
SELECT TxnDate, CAST(SUM(ISNULL(DurationMilliseconds, 0.0)) * 0.9 As Decimal(19,2)) [DurationMilliseconds90percent]
FROM your_table
GROUP BY TxnDate
你说的90值是什么意思?90%值?是否为(持续毫秒-开始毫秒)*0.9
?@CurseStacker其90%…持续毫秒列将在您所需的输出中非常有用,不是吗?@Raptor:Ignore Startmiliseconds列。。我想看看一个系统在90%的时间里需要多少时间。