您的位置:首页 > 数据库

2、SQL基础整理(聚合函数)

2014-12-15 15:27 232 查看

聚合函数

--求平均

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: