当前位置:网站首页>Oracle group statistics query
Oracle group statistics query
2022-06-27 10:55:00 【Mr. Li, a prodigy】
If a worker wants to do a good job, he must sharpen his tools first
Articles are constantly updated , You can search by wechat 【 Xiaoqi JAVA interview 】 First time reading , reply 【 Information 】 Access to benefits , reply 【 project 】 Get the source code of the project , reply 【 The resume template 】 Get resume template , reply 【 Learning Roadmap 】 Get a learning roadmap .

List of articles
One 、 Group function
Sum up :sum()
Average :avg()
minimum value :min()
Maximum :max()
1、 Query the average age of students
select avg(age) from student;
2、 Query the maximum age of students
select max(age) from student;
3、 Query the maximum and minimum age of students
select max(age),min(age) from student;
4、 Query the total age of students
select sum(age) from student;
Two 、COUNT() function
count() Functions can be written in three ways , They are as follows
count(*): It can accurately return the total number of records in the table .
count( Field ): Statistics are not null All data volume of .
count(distinct Field ): The amount of data after de duplication .
1、 Query the amount of data in the student table
select count(*) from student;
2、 The name in the query student table is not null The amount of data
select count(name) from student;
3、 Query the amount of data with no duplicate names in the student table
select count(distinct name) from student;
3、 ... and 、 Grouping statistics
group by: Group statistical functions
1、 Query the average age of students in each class in the student table , Group by class
select avg(age) from student group by class;
2、 Query the average age of students in each region in the student table , Group by Region
select avg(age) from student group by add;
Be careful : If you don't use group by sentence , that select Only statistical functions are allowed in clause , Other fields are not allowed . For example, query the number of all students , And it is not allowed to find out the student's name .
error sql:select name,count() from student;
correct sel:select count() from student;
Be careful : If you use group by sentence , that select Only... Is allowed in clause group by Statement field , Other fields are not allowed . For example, query the total number of students according to the class , And all student names are not allowed .
error sql:select name,class,count() from student group by class;
correct sql:select class,count() from student group by class;
Four 、 Multi table query and grouping statistics
Grouping statistics can be used with multi table queries .
1、 Check the student list id And teacher table sid Same student name , And count the number of students in groups according to their names
select s.name,count(*) from student s,teacher t where s.id = t.sid group by s.name;
5、 ... and 、HAVING Clause
having Is in group by After the statement , So go ahead group by After grouping, it can be based on having Clause to filter
1、 Query the class and average age of students in the student table , And group according to class , Then the average age is greater than 10 Class and grade check
select class,avg(age) from student group by class having avg(age) > 10;
6、 ... and 、 summary
The relevant contents here have not been sorted out yet , The article continues to be updated later , Recommended collection .
The commands involved in the article must be typed several times each like me , Only in the process of knocking can you find out whether you really master the command .
You can search by wechat 【 Xiaoqi JAVA interview 】 First time reading , reply 【 Information 】 Access to benefits , reply 【 project 】 Get the source code of the project , reply 【 The resume template 】 Get resume template , reply 【 Learning Roadmap 】 Get a learning roadmap .
边栏推荐
- [从零开始学习FPGA编程-47]:视野篇 - 第三代半导体技术现状与发展趋势
- Oracle连接MySQL报错IM002
- Win10快捷键整理
- Future & CompletionService
- Concepts of concurrency, parallelism, asynchronism, synchronization, multithreading and mutual exclusion
- 三层架构中,数据库的设计在哪一层实现,不是在数据存储层吗?
- Imeta: a collection of imagegp+ video tutorials of high-value drawing websites, which has been cited 360 times (220625 updates)
- .NET6接入Skywalking链路追踪完整流程
- Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.1 spanning tree protocol (STP)
- Product strength benchmarking seal /model 3, with 179800 pre-sales of Chang'an dark blue sl03
猜你喜欢

如何在 Methodot 中部署 JupyterLab?

Native JS implements page scroll bar loading data and page drop-down loading content

Analysis of mobile ar implementation based on edge computing (Part 2)

Write it down once Net analysis of a property management background service stuck

If you find any loopholes later, don't tell China!

audiotrack与audioflinger

Codeforces Round #786 (Div. 3) ABCDE

User authentication technology

Glide缓存机制

Working at home is more tiring than going to work at the company| Community essay solicitation
随机推荐
Audiotrack and audiolinker
Future & CompletionService
基于swiftadmin极速后台开发框架,我制作了菜鸟教程[专业版]
Frequently asked questions about closures
Product strength benchmarking seal /model 3, with 179800 pre-sales of Chang'an dark blue sl03
flutter 微信分享
数据库之元数据
Ubuntu手动安装MySQL
Win10快捷键整理
Leetcode to do questions
Glide缓存机制
浅析基于边缘计算的移动AR实现(中)
Error im002 when Oracle connects to MySQL
Memory compression for win10
leetcode:522. Longest special sequence II [greed + subsequence judgment]
iMeta:高颜值绘图网站imageGP+视频教程合集,已被引360次(220625更新)
三层架构中,数据库的设计在哪一层实现,不是在数据存储层吗?
【TcaplusDB知识库】Tmonitor单机安装指引介绍(二)
居家办公竟比去公司上班还累? | 社区征文
leetcode:968. Monitor the binary tree [tree DP, maintain the three states of each node's subtree, it is very difficult to think of the right as a learning, analogous to the house raiding 3]