SELECT 列1, 列2, ... FROM 表名 GROUP BY 列1, 列2, ...;
SELECT department, COUNT(*) FROM employees GROUP BY department;
CREATE TABLE students (id INT, name VARCHAR(50), score INT); INSERT INTO students (id, name, score) VALUES (1, 'Tom', 90); INSERT INTO students (id, name, score) VALUES (2, 'Jerry', 80); INSERT INTO students (id, name, score) VALUES (3, 'Alice', 70); INSERT INTO students (id, name, score) VALUES (4, 'Bob', 80); INSERT INTO students (id, name, score) VALUES (5, 'Cindy', 90); SELECT score, COUNT(*) FROM students GROUP BY score;
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com