ろ讌れ 覦覯 糾 豈 蟇一 豌 覿覿 る 伎企. ろ讌る 螻蠍 襯 蟆一 覦覯朱 れ螻 螳 螻旧 襷れ.
- 一危一 豐 螳, Max螳, Min螳 蟲. Max螳, Min螳 蟲 伎豺襯 蟇壱 蟆 譬.
- ろ讌れ 覦覯 伎 螻蠍 (k)襯 蟲.
- 螻 蟲伎 螻蠍 k襯 伎 螳 覯襯 蟲.
- 蟲伎 覯襦 一危磯ゼ 蟲覿.
れ SQL Server 2005 T-SQL 蟲 企.
DECLARE
@k int
, @r bigint
, @avg bigint
, @sigma bigint
, @min bigint
, @max bigint
, @cnt int
, @min_real bigint
, @max_real bigint
--1 + (LOG10(N) / LOG10(2))
SELECT
@sigma = STDEV(Score)
, @avg = AVG(Score)
, @min_real = MIN(Score)
, @max_real = MAX(Score)
FROM #Score
-- 伎豺 蟇壱 蟲螳 蟲.: 蠏 - (1.5 * 譴ク谿) ~ 蠏 + (1.5 * 譴ク谿)
SELECT
@r = (MAX(Score) - MIN(Score)) / (1 + (LOG10(COUNT(*)) / LOG10(2)))
, @k = (1 + (LOG10(COUNT(*)) / LOG10(2)))
, @cnt = COUNT(*)
, @min = MIN(Score)
, @max = MAX(Score)
FROM #Score
WHERE Score > @avg - (3 * @sigma)
AND Score < @avg + (3 * @sigma)
;WITH Dumy(Seq)
AS
(
SELECT 1 Seq
UNION ALL
SELECT Seq + 1 FROM Dumy
WHERE Seq + 1 <= @k
), Grade
AS
(
SELECT
(@k - Seq ) + 1 Grade
, @min + ((Seq-1) * @r) BeginScore
, @min + (Seq * @r) EndScore
FROM Dumy
), RealGrade
AS
(
SELECT Grade, BeginScore, EndScore FROM Grade
UNION ALL
SELECT Grade + 1, @min_real, EndScore + 1
FROM Grade
WHERE Grade = (SELECT MAX(Grade) FROM Grade)
UNION ALL
SELECT Grade - 1, BeginScore + 1, @max_real
FROM Grade
WHERE Grade = (SELECT MIN(Grade) FROM Grade)
)
SELECT
B.Grade
, COUNT(*) AccountCnt
, SUM(NetAMT) NetAMT
FROM #Score A
INNER JOIN RealGrade B
ON A.Score BETWEEN B.BeginScore AND B.EndScore
GROUP BY
B.Grade
ORDER BY 1