聚合函数
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. 《从零开始学Swift》学习笔记(Day 28)——总结使用问号(?)和感叹号(!)

    原创文章,欢迎转载.转载请注明:关东升的博客 在使用可选类型和可选链时,多次使用了问号(?)和感叹号(!),但是它们的含义是不同的,下面我来详细说明一下. 1. 可选类型中的问号(?) 声明这个类型是 ...

  2. Spring JDBC-混合框架的事务管理

    ​ Spring 抽象的 DAO 体系兼容多种数据访问技术,它们各有特色,各有千秋. Hibernate 是非常优秀的 ORM 实现方案,但对底层 SQL 的控制不太方便 MyBatis 则通过模板化 ...

  3. Solr 查询时候关键期 编码问题

    背景架构: 中间是dubbo 调用, 其实还是编码问题!没啥大问题!记录下

  4. 整理前端css/js/jq常见问题及解决方法(3)

    jq: 1.prepend(参数);//将参数内容前置再某元素内部; eg: <div id="div1">奇妙能力歌</div> $("#div ...

  5. 随机生成六位验证码函数版(python)

    import random def code(n=6,alpha=True): s = '' # 创建字符串变量,存储生成的验证码 for i in range(n): # 通过for循环控制验证码位 ...

  6. win7安装laravel

    使用Packagist 镜像 建立一个composer.json文件,内容如下: { "name": "laravel/laravel", "desc ...

  7. 我的Java开发学习之旅------>二进制、八进制、十进制、十六进制之间转换

    一. 十进制与二进制之间的转换  (1) 十进制转换为二进制,分为整数部分和小数部分  ① 整数部分  方法:除2取余法,即每次将整数部分除以2,余数为该位权上的数,而商继续除以2,余数又为上一个位权 ...

  8. Apache JServ Protocol (AJP)

    The Apache JServ Protocol (AJP) is a binary protocol that can proxy inbound requests from a web serv ...

  9. 部署Jenkins+docker集成环境

    环境: 主机(mac osx)和虚拟机(Ubuntu 16.04) mac osx系统,运行Jenkins Ubuntu16.04系统,运行docker(用Ubuntu14.04镜像创建一个docke ...

  10. SQL SREVER, ORACLE数据库连接字符串

    采用windows身份验证模式 Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;