聚合函数
count 返回查询结果的条数
max 返回查询结果的最大值
min 返回查询结果的最小值
sum 返回查询结果的和
avg 返回查询结果的平均值
 
统计分数大于等于90的人数:
mysql> select count(*) from new_student
        -> where score >="90"; 
 
 
使用distinct剔除字段值重复的条数
mysql> select count(distinct score) from new_student
        -> where score >="90";
 
统计最高分-max
mysql> select max(score) from new_student;
 
统计最低分-min
mysql> select min(score) from new_student;
 mysql> select min(score) from new_student
        -> where score >=60;
 
统计分数大于等于90的分数的和-sum
 mysql> select sum(score) from new_student
        -> where score >="90";
 
统计平均数-avg
 mysql> select avg(score) from new_student
        -> where score >="80";
 
分组查询
语法格式;
select [聚合函数] 字段名 from 表名
where 查询条件
group by 字段名
having 过滤条件
 
mysql> select score,count(*) from new_student
        -> where score >=80
        -> group by score;
 
mysql> select score,count(*) from new_student
        -> where score >=80             
        -> group by score
        -> having score >=90;
注:having子语句与where子语句区别:前者在分组后对记录进行过滤,后者在分组前对记录进行过滤
 
 
mysql> select score,count(*) from new_student

        -> where score >=80
        -> group by score
        -> having score >=90
        -> order by score desc;
 
 
 
联合查询
语法格式
select 语句
union [all]
select 语句
...
 注:联合查询结果使用第一个select语句中的字段名
 
mysql> select * from test_wl
        -> union
        -> select * from test_wu;
 
 
 

最新文章

  1. 拓扑排序(三)之 Java详解
  2. Android ANR产生的原理和如何避免
  3. gitlab&fengoffice的ldap配置
  4. 一个使用微软Azure blob实现文件下载功能的实例-附带源文件
  5. div中加入iframe,可以实现Ajax的功能
  6. Android异步操作总结
  7. Java多线程中join方法详解
  8. HDU 1513 Palindrome:LCS(最长公共子序列)or 记忆化搜索
  9. Python第一天---第一个Python程序
  10. Android性能优化之Bitmap的内存优化
  11. Jmeter的Body Data里输入中文时乱码
  12. c# 号码记录,车友
  13. Nginx---(Server虚拟主机)
  14. openSUSE搭建OpenVPN
  15. ThinkingInJava 学习 之 0000006 复用类
  16. RecyclerView的点击事件添加-------接口回调的形式添加
  17. Spring Batch中job的启动,停止,放弃操作
  18. 【微信小程序】---线上环境搭建
  19. 马尔可夫毯(Markov blanket)
  20. Redis&PHP的使用安装-windows版

热门文章

  1. springboot1.4下hystrix dashboard Unable to connect to Command Metric Stream解决办法
  2. 转:: 刺鸟:用python来开发webgame服务端(1)
  3. jconsole监控JVM
  4. 三、docker官网注册docker id
  5. 打日志--以python为例
  6. 接口测试工具 — postman(post请求)
  7. 中文Ubuntu里用户目录里的路径改成英文
  8. RecyclerView添加分割线
  9. Simple Tips for Collection in Python
  10. 怎样在不对控件类型进行硬编码的情况下在 C#vs 中动态添加控件