📅  最后修改于: 2020-11-13 00:51:45             🧑  作者: Mango
SQLite COUNT函数用于获取表达式的总数。
句法:
SELECT COUNT(aggregate_expression)
FROM tables
[WHERE conditions];
将MAX函数与GROUP BY子句一起使用时的语法:
SELECT expression1, expression2, ... expression_n
COUNT(aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n;
范例1:
我们有一个名为“ STUDENT”的表,其中包含以下数据:
计算“年龄”大于22的“学生”表中的所有学生人数。
SELECT COUNT(*) AS "Number of students"
FROM STUDENT
WHERE AGE > 22;
输出:
范例2:
将GROUP BY子句与COUNT函数:
计算年龄大于22岁的具有特定姓名的学生人数,然后按姓名将学生分组。
SELECT NAME, COUNT(*) AS "Number Of Students"
FROM STUDENT
WHERE AGE > 22
GROUP BY NAME;
输出: