五、Oracle 分组查询、视图
一。分组函数
1.avg:平均分
2.sum:求和
3.max:最大值
4.min:最小值
注意:前面四个必须针对数值字段,且参数只能是一个
5.count:求个数
二。分组查询
1。语法是 group by 分组字段1,分组字段2...
2.分组后可以使用分组函数。
3.分组函数不能和其他字段一起显示,除了分组字段。
4.分组查询之后还要做条件限制的话,用having子句
5.关键字的顺序:select ...from...where...group by...having...order by....
三。子查询:在查询的结果上继续查询
1.将查询结果作为新的表继续查询
select * from student a,(select * from grade) b where a.xxid=b.xxid
2.将查询结果作为查询条件来使用
select * from grade where student in (select st_id from student where st_sex='女')
四。视图(view)
1.作用。保存查询结果,方便反复调用
2.语法:create view 视图名 as 查询语句
3.注意:视图的数据可以修改,但不建议修改。统计后的数据,用了函数的数据,以及非键保留值得数据都不能修改
练习:
- 1.查询每门课程的最高分和最低分,显示如下
- java最高分:99 最低分:33
- oracle最高分:100 最低分: 55
- select a.dic_name,max(b.socre) 最高分,min(b.socre) 最低分
- ,avg(b.socre) 平均分,sum(b.socre) 总和 from diclipline a,grade b
- where a.dic_id=b.diclipline
- group by a.dic_name
- 2.查询每门成绩的平均分和总分
- 3.查询java1班参加oracle考试的人数
- select count(rownum) from squad a3,diclipline b3,grade c3,student d3 where a3.squad_id=d3.st_class
- and b3.dic_id=c3.diclipline and c3.student=d3.st_id
- and a3.squad_name='java1班' and b3.dic_name='oracle'
- 4.查询每个班j2ee考试的平均分,并按降序排序
- select a4.squad_name,avg(c4.socre) from squad a4,diclipline b4,grade c4,student d4 where a4.squad_id=d4.st_class
- and b4.dic_id=c4.diclipline and c4.student=d4.st_id and b4.dic_name='j2ee'
- group by a4.squad_name order by avg(c4.socre) desc
- 5.查询oracle考试平均成绩不及格的班级有哪些
- select avg(c5.socre),a5.squad_name,b5.dic_name from squad a5,diclipline b5,grade c5,student d5 where a5.squad_id=d5.st_class
- and b5.dic_id=c5.diclipline and c5.student=d5.st_id and b5.dic_name='oracle'
- group by a5.squad_name,b5.dic_name having avg(c5.socre)>60
- 6.查询所有java考试不及格的学员是哪些
- select * from grade where socre<60
五、Oracle 分组查询、视图的更多相关文章
- ORACLE分组查询和统计等
select flow_id,rw from (select t.flow_id ,rownum as rw from apex_030200.wwv_flow_list_templates t) ...
- Django day08 多表操作 (五) 聚合,分组查询 和 F,Q查询
一:聚合,分组查询 二:F, Q查询
- oracle分组查询实例ORA-00979和ORA-00937错误分析
select J.ZWJGH,J.CZZXBH,J.JZZT,J.CWNY,J.JZPZH sum(J.FSE)<!-- 聚合函数字段没在分组条件中--> from JZPZXX J &l ...
- oracle分组查询
分组函数 在分组函数中,如果有一个查找项分组,其他项必须也分组,比如下面的语句会报错,因为sal分组了,而ename没有分组: 1.显示工资最高的员工: 2.显示所有员工的平均工资: 2.1使用系统函 ...
- oracle 分组查询
常用的函数: ·:统计个数:COUNT(),根据表中的实际数据量返回结果: ·:求和:SUM(),是针对于数字的统计,求和 ·:平均值 ...
- 【知识库】-数据库_MySQL之基本数据查询:子查询、分组查询、模糊查询
简书作者:seay 文章出处: 关系数据库SQL之基本数据查询:子查询.分组查询.模糊查询 回顾:[知识库]-数据库_MySQL常用SQL语句语法大全示例 Learn [已经过测试校验] 一.简单查询 ...
- Oracle总结【SQL细节、多表查询、分组查询、分页】
前言 在之前已经大概了解过Mysql数据库和学过相关的Oracle知识点,但是太久没用过Oracle了,就基本忘了...印象中就只有基本的SQL语句和相关一些概念....写下本博文的原因就是记载着Or ...
- oracle 基础SQL语句 多表查询 子查询 分页查询 合并查询 分组查询 group by having order by
select语句学习 . 创建表 create table user(user varchar2(20), id int); . 查看执行某条命令花费的时间 set timing on: . 查看表的 ...
- .Net程序员学用Oracle系列(21):分组查询(GROUP BY)
1.GROUP BY 标准分组 1.1.GROUP BY 概述 1.2.WHERE 和 HAVING 的区别? 2.GROUP BY 扩展分组 2.1.ROLLUP 分组 2.2.CUBE 分组 2. ...
随机推荐
- react学习(三)之生命周期/refs/受控组件 篇
挂载/卸载 //在类组件中 class Clock extends React.Component { constructor(props) { super(props); this.state = ...
- 二进制安装 kubernetes 1.12(四) - 部署 Node 节点组件
在 master 上操作 vi /etc/profile export PATH=/opt/kubernetes/bin:$PATH source /etc/profile 将 kubelet-boo ...
- elementUI vue upload完整示例
elementUI 和vue 还有axios +java的完整示例, 代码敲了很久, 累死了, 以后用就直接复制了 ,很值吧!!! 1.html <!DOCTYPE html> <h ...
- vue从入门到进阶:Class 与 Style 绑定(四)
绑定 HTML Class 对象语法 ①.添加单个class: <div v-bind:class="{ active: isActive }"></div> ...
- mysql练习----SUM and COUNT/zh图(二)
世界国家概况 GROUP BY 和 HAVING 通过包括一个GROUP BY子句功能, SUM并将COUNT 其应用于共享值的项目组.当你指定 GROUP BY continent 结果是每个不同的 ...
- [20180926]共享池中的NETWORK BUFFER.txt
[20180926]共享池中的NETWORK BUFFER.txt --//最近几天一直在探究SQL*Net more data from client 相关等待事件,发现SDU相关,自己也网上探究一 ...
- [20180808]exists and not exists.txt
[20180808]exists and not exists.txt --//生产系统遇到的一个性能问题,通过例子来说明: 1.环境:SCOTT@test01p> @ ver1 PORT_ST ...
- mssql sql server ceiling floor 函数用法简介
摘自: http://www.maomao365.com/?p=5581摘要: 下文主要讲述ceiling.floor函数的功能及举例说明 一.ceiling floor函数功能简介 ceiling ...
- python连接sqlserver数据库
1.准备工作 python3.6连接sqlserver数据库需要引入pymssql模块 pymssql官方:https://pypi.org/project/pymssql/ 没有安装的话需要: pi ...
- MySQL复制错误1837的相关缺陷一例
故障现象 主从gtid报错,复制错误1837,这个复制故障可以说是第一次遇到. Last_Errno: 1837 Last_Error: Error 'When @@SESSION.GTID_NEXT ...