我有一个学生姓名和分数列表,存储在如下表中。
CREATE TABLE StudentsList(StudentId INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Name VARCHAR(50),
Marks INT);
INSERT INTO StudentsList(Name, Marks)
VALUES('Student A', 20),
('Student B', 45),
('Student C', 90),
('Student D', 81),
('Student E', 50),
('Student F', 10),
('Student G', 85),
('Student H', 41),
('Student I', 66),
('Student J', 65),
('Student K', 05),
('Student L', 20),
('Student M', 19),
('Student N', 80),
('Student O', 90),
('Student P', 91),
('Student Q', 10),
('Student R', 29);
我想根据他们整体贡献的分数范围和百分比对学生的数量进行分组。
MarkRange NoOfStudents Percentage
0 - 20 4 22.22
20 - 50 5 27.77
50 - 70 3 16.66
70 - 90 3 16.66
90 3 16.66
我尝试了以下查询并为 0 -20 之间的学生带来了结果
SELECT COUNT(*) , COUNT(*)/(T.total)* 100
FROM StudentsList,
(SELECT COUNT(*) AS total
FROM StudentsList) AS T
WHERE Marks >= 0 and Marks < 20
如何使用单个查询来做到这一点