我想繪製一個面積圖的學生每積累分數沒有學生在一個軸上和累積百分比的標記在其他。 我嘗試下面的代碼,並且需要幫助查找%頻率:如何獲得跑步總數和跑步總數的一組範圍的頻率百分比
USE [newexam2017]
GO
StoredProcedure [dbo].[sp_range] Script Date: 06/03/2017 10:50:43
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_range]
@sub_code nvarchar(10)
AS
BEGIN
SET NOCOUNT ON;
CREATE TABLE #range
(
Interval varchar(10),
NoOfStudents varchar(8)
);
INSERT INTO #range(Interval) values('10-20'),('21-30'),('31-40'),('41-
50'),('51-60'),('61-70'),('71-80'),('81-90'),('91-100')
SELECT t.Interval , ISNULL(count(t.Interval),0) as [NoOfStudents]
FROM (
SELECT CASE
WHEN Total_marks BETWEEN 10 and 20 THEN '10-20'
WHEN Total_marks BETWEEN 21 and 30 THEN '21-30'
WHEN Total_marks BETWEEN 31 and 40 THEN '31-40'
WHEN Total_marks BETWEEN 41 and 50 THEN '41-50'
WHEN Total_marks BETWEEN 51 and 60 THEN '51-60'
WHEN Total_marks BETWEEN 61 and 70 THEN '61-70'
WHEN Total_marks BETWEEN 71 and 80 THEN '71-80'
WHEN Total_marks BETWEEN 81 and 90 THEN '81-90'
WHEN Total_marks BETWEEN 91 and 100 THEN '91-100'
end as Interval
from newexam2017_transctn where [email protected]_code) t
right join #range i on i.Interval = t.Interval
group by t.Interval
;WITH cummulative AS
(
SELECT Interval,NoOfStudents,RunningTotal= NoOfStudents
FROM #range
WHERE Interval = '10-20'
UNION ALL
SELECT y.Interval, y.NoOfStudents, cummulative.RunningTotal +
y.NoOfStudents
FROM cummulative INNER JOIN #range AS y
ON y.NoOfStudents = cummulative.NoOfStudents + 1
)
SELECT Interval, NoOfStudents, RunningTotal
FROM cummulative
ORDER BY Interval
OPTION (MAXRECURSION 10000);
DROP TABLE #range;
END
,但我得到了以下錯誤:
類型不錨和列遞歸部分之間的匹配
和它僅示出了2個3範圍和空爲第一範圍10-20
希望表看起來像:
間隔|學生數| |學生總數累計學生數
10-20 | 0 | 0
20-30 | 3 | 3
30-40 | 12 | 15
40-50 | 11 | 26
50-60 | 35 | 61
60-70 | 15 | 76
70-80 | 14 | 90
80-90 | 6 | 96
90-100 | 4 | 100
fyi:'10-20'是一個整數,''10-20''是一個字符串。 – HABO
mybad..but仍然不能解決問題 –
請提供您試圖實現的輸出樣本。 –