聚合函数
--求平均
select AVG(age) as 年龄 from xuesheng
select AVG(chinese) as 语文 from xuesheng where class = 1
*只能对数字类型的进行操作
--求个数
select COUNT(*) from xuesheng/*查询表中有多少条数据*/
select COUNT(*) from xuesheng where name like ‘王%‘
select COUNT(distinct class) from xuesheng
(两个班级)
--求最大值
select MAX(chinese) from xuesheng where class = 1
--求最小值
select MIN(chinese) from xuesheng where class = 1
--求和
select SUM(chinese) from xuesheng
(以上函数括号中都可以加distinct,默认为all)
组合使用
select AVG(age) as 平均年龄,COUNT(*)as 人数 from xuesheng where class = 1
时间: 2024-10-02 23:12:13