$ Cid $ _ GET [id];
$cid = $_GET['id'];
Reply content: divide by 10 and use group by and count aggregate again. Let's make SQL into a dynamic language. It's really true-I'm a cainiao and can write it at will ···
DECLARE @ grade TABLE (
[Id] [int] IDENTITY (1, 1) not null,
[CId] [int] not null,
[SId] [int] not null,
[Sgrade] [int] NOT NULL
);
Insert into @ grade (cId, sId, sgrade) VALUES (1, 0, 0 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 1, 3 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 2, 6 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 3, 9 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 4, 12 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 5, 15 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 6, 18 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 7, 21 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 8, 24 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 9, 27 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 10, 30 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 11, 33 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 12, 36 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 13, 39 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 14, 42 );
Insert into @ grade (cId, sId, sgrade) VALUES (1,15, 45 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 16, 48 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 17, 51 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 18, 54 );
Insert into @ grade (cId, sId, sgrade) VALUES (1,19, 57 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 20, 60 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 21, 63 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 22, 66 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 23, 69 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 24, 72 );
Insert into @ grade (cId, sId, sgrade) VALUES (25-25, 75 );
Insert into @ grade (cId, sId, sgrade) VALUES (1,26, 78 );
Insert into @ grade (cId, sId, sgrade) VALUES (1,27, 81 );
Insert into @ grade (cId, sId, sgrade) VALUES (1,28, 84 );
Insert into @ grade (cId, sId, sgrade) VALUES (1,29, 87 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 30, 90 );
Insert into @ grade (cId, sId, sgrade) VALUES (1,31, 93 );
Insert into @ grade (cId, sId, sgrade) VALUES (1,32, 96 );
Insert into @ grade (cId, sId, sgrade) VALUES (1, 33, 99 );
Insert into @ grade (cId, sId, sgrade) VALUES (100 );
Select count (sId) [Count], sgrade/10*10 lowersgrade, sgrade/10*10 + 9 uppersgrade
FROM @ grade cs WHERE cs. cId = 1
Group By sgrade/10;
Select count (1) [Count], st * 10 lowersgrade, st * 10 + 9 uppersgrade FROM
(SELECT sId, sgrade/10 st
FROM @ grade cs WHERE cs. cId = 1) t
Group by t. st;
If GO is computed using SQL, I don't know whether there are functions such as frequency. I usually use the remainder. For example, if the group distance is 7, divide the score by 7 to calculate the remainder, and then use the score-remainder/7 to get the group number.