当前位置: 首页 > news >正文

mysql基础(3)-高级查询

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

 

转载于:https://www.cnblogs.com/wujiadong2014/p/5717198.html

相关文章:

  • SpringMVC3.1.1+Spring3.1.1+Hibernate4+Velocity+EasyUI+ZTree实现RBAC基于角色的访问控制(二)...
  • 设置RMAN的备份路径
  • uboot移植(三)——uboot mkconfig脚本分析
  • .NET文档生成工具ADB使用图文教程
  • Java中Enum枚举的使用
  • 【解决数据中心网速慢的八个检查必备步骤】
  • Centos 5.6 下安装XEN虚拟机以及EMOS
  • UVA1339 UVALive3213 POJ2159 ZOJ2658 Ancient Cipher【密码】
  • UVALive 4660 A+B
  • 切割Nginx日志的脚本
  • pg 学习资料
  • Ntp配置文件详解
  • httpd 启动报错“”Permission denied: make_sock: could not bind to address [::]:80“”
  • 定制yum仓库
  • WMIC Query SCSI Info
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • go append函数以及写入
  • JavaScript设计模式之工厂模式
  • npx命令介绍
  • php的插入排序,通过双层for循环
  • Python3爬取英雄联盟英雄皮肤大图
  • scala基础语法(二)
  • vue脚手架vue-cli
  • 两列自适应布局方案整理
  • 区块链分支循环
  • 区块链将重新定义世界
  • 使用docker-compose进行多节点部署
  • 微服务框架lagom
  • 微服务入门【系列视频课程】
  • 一份游戏开发学习路线
  • 用Canvas画一棵二叉树
  • MyCAT水平分库
  • Salesforce和SAP Netweaver里数据库表的元数据设计
  • #100天计划# 2013年9月29日
  • #快捷键# 大学四年我常用的软件快捷键大全,教你成为电脑高手!!
  • #数学建模# 线性规划问题的Matlab求解
  • (C#)一个最简单的链表类
  • (C)一些题4
  • (pojstep1.3.1)1017(构造法模拟)
  • (zhuan) 一些RL的文献(及笔记)
  • (zt)基于Facebook和Flash平台的应用架构解析
  • (二)构建dubbo分布式平台-平台功能导图
  • (附源码)springboot猪场管理系统 毕业设计 160901
  • (附源码)ssm基于web技术的医务志愿者管理系统 毕业设计 100910
  • (机器学习-深度学习快速入门)第一章第一节:Python环境和数据分析
  • (学习日记)2024.04.04:UCOSIII第三十二节:计数信号量实验
  • (转)Google的Objective-C编码规范
  • (转)机器学习的数学基础(1)--Dirichlet分布
  • .axf 转化 .bin文件 的方法
  • .net 程序 换成 java,NET程序员如何转行为J2EE之java基础上(9)
  • .NetCore 如何动态路由
  • /etc/apt/sources.list 和 /etc/apt/sources.list.d
  • [ C++ ] STL_stack(栈)queue(队列)使用及其重要接口模拟实现
  • [Android学习笔记]ScrollView的使用
  • [C#]winform制作仪表盘好用的表盘控件和使用方法