1. 建立數據庫
CREATE TABLE `class` (
-> `id` int(255) NOT NULL AUTO_INCREMENT,
-> `score` int(11) DEFAULT NULL,
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;
2. 隨機填充點數據
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)
3.需求,查找出0到60之間,每10一個區間的人數
SELECT elt(
INTERVAL(score, 0, 50, 60, 70, 80, 90, 100),
'<50', '50-60', '60-70', '70-80', '80-90', '90-100', '>=100') as score_level,
count(*) as counts
FROM class
GROUP BY elt(
INTERVAL(score, 0, 50, 60, 70, 80, 90, 100),
'<50', '50-60', '60-70', '70-80', '80-90', '90-100', '>=100'
);
![在這裏插入圖片描述](http://static.javashuo.com/static/loading.gif)