聚合函数
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;
 
 
 

mysql基础(3)-高级查询的更多相关文章

  1. MySQL基础架构之查询语句执行流程

    这篇笔记主要记录mysql的基础架构,一条查询语句是如何执行的. 比如,在我们从student表中查询一个id=2的信息 select * from student where id=2; 在解释这条 ...

  2. 10月17日下午MySQl数据库CRUD高级查询

    高级查询:1.连接查询 #适用于有外键关系的  没有任何关系没法用select * from Info,Nation #同时查询这俩表并把两表每个数据相互组合,形成笛卡尔积 select * from ...

  3. Mysql 基本语句 + 高级查询

    MySQL执行SQL脚本文件的命令: 从cmd进入mysql命令行模式: mysql> -uroot –prootpassword –Ddatabasename 如果是我本地的数据库,就相应修改 ...

  4. mysql中的高级查询

    以前学习的查询语法: select 字段名 from 表名 where 条件 其实,查询的语法变化很多: 1. select 可以查询表达式, 表达式就是 运算符+操作数. 比如 1 + 1 2 * ...

  5. MySQL基础7-分页查询

    1.分页查询(MySQL特有的,oracle中没有) 栗子1: 每页最多3条记录:pageSize=3:第一页:SELECT * FROM product LIMIT 0,3第二页:SELECT * ...

  6. mysql中的高级查询语句

    此随笔用到的数据全是来自  关于mysql中表关系的一些理解(一对一,一对多,多对多) 提及的    学院表,学生表,学生详情表,选课表,课程表 单标查询:(查看学生表的学生名单) select st ...

  7. MySql数据and高级查询

    1.CREATE TABLE grade(stuID INT AUTO_INCREMENT PRIMARY KEY NOT NULL,stuName VARCHAR(32),stuAge INT ) ...

  8. MySQL基础6-分组查询

    1.分组函数 需求20:查询所有商品平均零售价SELECT AVG(salePrice) FROM product 需求21:查询商品总记录数SELECT COUNT(id) count FROM p ...

  9. MySQL基础4-SQL简单查询(单表)

    1.SELECT语句 2.运算符的优先级 利用Navicat中的查询方法: 栗子1:查询所有货品信息 栗子2:查询所有货品的id,productName,salePrice 当查询错误的时候出现的界面 ...

  10. MySQL基础语句(查询)

    students表 id class_id name gender score 1 1 小明 M 90 2 1 小红 F 95 3 1 小军 M 88 4 1 小米 F 73 5 2 小白 F 81 ...

随机推荐

  1. Android 定时器Timer的使用

    定时器有什么用 在我们Android客户端上有时候可能有些任务不是当时就执行,而是过了一个规定的时间在执行此次任务.那么这个时候定时器的作用就非常有用了.首先开启一个简单的定时器 Timer time ...

  2. LeetCode Problem 9:Palindrome Number回文数

    描述:Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...

  3. poj 3270(置换 循环)

    经典的题目,主要还是考思维,之前在想的时候只想到了在一个循环中,每次都用最小的来交换,结果忽略了一种情况,还可以选所有数中最小的来交换一个循环. Cow Sorting Time Limit: 200 ...

  4. Win7系统安装 MySQL 5.7.23

    1. 下载 MySQL 5.7版本:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 2. 解压到指定文件夹,mysql根目录下创建my ...

  5. Travel(最短路)

    Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n1,2,…,n. Amo ...

  6. JS实现全选,全不选

    <script type="text/javascript"> function selectItem() { document.getElementById(&quo ...

  7. 监听浏览器使用不同版本js并且处理ie兼容getElementByClassName

    if(window.addEventListener){ document.write('<script src="js/jquery-2.1.4.min.js">&l ...

  8. 2014-08-28——移动端,触摸事件 touchstart、touchmove、touchend、touchcancel

    1.Touch事件简介在移动终端上的web页面触屏时会产生ontouchstart.ontouchmove.ontouchend.ontouchcancel 事件,分别对应了触屏开始.拖拽及完成触屏事 ...

  9. unity坑faq

    遇到的坑记录下来,大都都是听说,没有实测 1. Graphics.copyTexture,在某些机型上不支持从不同类型拷贝 2. msaa 小米mix2不支持,晓龙845 3. android4.2下 ...

  10. 避免每次都用sudo使用docker

    默认安装完 docker 后,每次执行 docker 都需要运行 sudo 命令,非常浪费时间影响效率.如果不跟 sudo,直接执行 docker images 命令会有如下问题: FATA[0000 ...