Re: [SQL ] SQL GROUP BY 語法怎麼用

作者: pinkykk (品奇)   2013-12-24 01:04:37
類似這樣?
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

Links booklink

Contact Us: admin [ a t ] ucptt.com