当前位置:网站首页>C#语言和SQL Server数据库技术
C#语言和SQL Server数据库技术
2022-07-25 09:17:00 【yushang_zhang】
连接查询和分组查询
一、使用Group By进行分组
1.分组的本质就是分类,然后合并同类项
2.分组是为了下一步的聚合函数能够对不同分类的数据分别进行统计
3.查询男生,女生的数据量
4.查询每个分类的图书有多少本
5.注意:使用分组的查询语句,能够出现在结果列的数据需要满足以下条件之一:
a、参与分组的列
b、使用了聚合函数的列
二、使用having语句筛选分组结果
1.查询每个分类的图书有多少本,再按照图书数量降序排序
2.order by要放在group by的后面
3.查询每个分类的图书有多少本,其中过滤掉只有一本的分类数据
4.having语句用于对分组后的结果进行筛选
5.三个语句的执行顺序为:
where --》 group by --》 having
6.查询作者不为空的图书中,每个分类对相应的图书数量是多少,并过滤掉只有一本的分类数据
三、内联接查询
1.为了防止数据冗余,我们的数据通常都根据类别存储在不同的几张表中
2.如果想查看完整的数据,则需要从多张表中查询数据来组合为一个完整的查询结果
3.这就需要使用多表联查,而多表联查围绕的就是关联列(外键)进行的
4.关联查询:
a、内联接 inner join
b、外连接 outer join
5.内联接查询:
a、使用inner join ... on ... 关键字,其中inner可以省略
b、内联接查询在连接查询中最为常用
c、on 后面写的是连接的两张表的对应关系,即连接条件
d、只有两张表中都存在对应关系的数据才会显示
e、as 不仅可以用来给列取别名,也可以给表取别名
f、表名.* 表示显示这张表的所有列
g、可以通过where条件指定关联关系实现隐式内联接的写法
h、内联接中表的先后顺序仅表示有那张表发起查询,对查询结果行数不影响,即两表平等
i、一次可以来连接多张表,比如学生表、科目表、成绩表三表联查
四、外连接查询
1.内联接查询两表平等,只有符合连接条件的数据才能显示
2.与内联接相对的查询方式称为外联接查询,能够用于筛选不符合连接条件的记录
3.外连接查询的语法:
left outer join ... on ...
right outer join ... on ...4.外连接查询的特点:
a、外连接查询中参与连接的表有主从之分
b、以主表的每行数据匹配从表的数据列
c、符合条件的数据直接返回到结果集中
d、不符合条件的记录被填上null依旧返回到结果集中
e、主表的记录无论在子表中是否有匹配,都能保证出现在查询结果中
f、左表是主表的成为左外连接,右表有主表的成为右外连接
4.查询没有一条图书记录的图书分类信息
边栏推荐
- Silicon Valley classroom lesson 15 - Tencent cloud deployment
- C#语言和SQL Server数据库技术
- ActiveMQ -- AMQ of persistent mechanism
- Silicon Valley classroom lesson 12 - official account on demand course and live broadcast management module
- Shell script
- JDBC quick start
- registration status: 204
- 学习周刊-总第 63 期-一款开源的本地代码片段管理工具
- Live broadcast preview | how to build an enterprise cloud management platform in the cloudy era?
- The hole of scroll view in uniapp
猜你喜欢

2022-7-14 JMeter pressure test

Live broadcast preview | how to build an enterprise cloud management platform in the cloudy era?

Nacos搭建配置中心出现client error: invalid param. endpoint is blank

『每日一问』简单聊聊JMM/说说对JMM的了解

How to realize the drop-down option box of wechat applet

『每日一问』ReentrantLock加锁解锁

JS pop-up City filtering component matches mobile terminal

Network principle (2) -- network development

idea实用tips---如今将pom.xml(红色)改为pom.xml(蓝色)

Disable module (attribute node) in LabVIEW
随机推荐
『怎么用』观察者模式
Troubleshooting error: NPM install emojis list failed
Detailed explanation of pipeline pipeline mechanism in redis
@Scheduled源码解析
ActiveMQ -- persistent mechanism
『怎么用』代理模式
idea实用tips---如今将pom.xml(红色)改为pom.xml(蓝色)
How to avoid duplicate data when the database is high and distributed
360 degree drag panorama plug-in tpanorama.js
深入理解static关键字
黑马程序员JDBC
Bi business interview with data center and business intelligence (I): preparation for Industry and business research
Disable module (attribute node) in LabVIEW
redis操作利用游标代替keys
Nacos搭建配置中心出现client error: invalid param. endpoint is blank
activemq--可持久化机制之KahaDB
Ranking of data results in MySQL
一文搞懂为什么要同时重写equals方法和hashCode方法+实例分析
Learn about spark project on Nebula graph
Comparison between symmetric encryption and asymmetric encryption