类似这样?
DECLARE @T_MATH_SCORE AS TABLE (STU_NO INT, SCORE INT)
DECLARE @V_CNT INT = 0
WHILE(@V_CNT < 100)
BEGIN
SET @V_CNT = @V_CNT + 1
INSERT INTO @T_MATH_SCORE
SELECT @V_CNT, RAND()*100
END
SELECT STU_NO, SCORE, COUNT(1) OVER (PARTITION BY RNK)CNT FROM (
SELECT
STU_NO, SCORE, RANK()OVER(ORDER BY ABS(SCORE-1)/20) AS RNK
FROM @T_MATH_SCORE) SRC ORDER BY SCORE
※ 引述《s900362123 (s900362123)》之铭言:
: 请问 SQL GROUP BY 语法怎么用
: 我有一个资料表叫成绩 里面有数学成绩
: 我想要0~20,21~40,41~60,61~80,81~100
: 计算每个群组的人数
: 输出一起输出 不用字段名称 但要按照顺序
: 请帮忙想 很急 TKS