DQL查询数据


DQL

(Data Query Language:数据查询语言)

  1. 所有的查询操作都要用到它 select
  2. 简单的查询,复杂的查询都要用到它
  3. 数据库最核心的语言,最重要的语言
  4. 使用频率最高的语言

指定查询字段

-- 查询所有的学生  select 字段 from 表
select * from student
-- 查询指定字段
select studentno,studentname from student
-- 给结果起一个名字 , As,可以给字段起别名,也可以给表起别名
select studentno as 学号,studentname as 学生姓名 from student
select studentno 学号,studentname 学生姓名 from student

-- 函数 concat(a,b)
select CONCAT('姓名:',studentname) as 新名字 from student

语法:select 字段 from 表
有时候,列的名字不是那么的见名之意,我们可以用as给字段起别名
字段名 as 别名 或者是 表名 as 表别名

去重 distinct

作用:去除select查询出来的结果中重复的数据,重复的数据只显示一条

-- 查询一下有哪些同学参加了考试
select * from result -- 查询全部的考试成绩
select studentno from result -- 查询有哪些学生参加了考试
select distinct studentno from result -- 去重

数据库的列(表达式)

select version() -- 查询系统版本号(函数)
select 100*3-2 -- 用来计算(表达式)
select @@auto_increment_increment -- 查询自增的步长(变量)
 
-- 学生考试成绩+1分查看
select studentno,studentresult+1 as '提分后' from result

数据库中的表达式:文本值,列,null,函数,计算表达式,系统变量

select 表达式 from 表

where条件子句

作用:检索符合条件的值

搜索的条件都是由一个或者多个表达式组成!结果都是布尔值

逻辑运算符

在这里插入图片描述

select studentno,studentresult from result

-- 查询考试成绩在95~100之间的
-- and &&
select studentno,studentresult from result 
where studentresult>=95 and studentresult<=100
-- 模糊查询(区间)
select studentno,studentresult from result 
where studentresult between 95 and 100
-- ! not
select studentno,studentresult from result 
where not studentno=1000

模糊查询:比较运算符

在这里插入图片描述

-- ===========模糊查询========================
-- 查询姓张的同学
-- like结合%(代表0到任意个字符) _(一个字符)
select studentno,studentname from student
where studentname like '张%'
-- 查询姓张的同学,名字只有两个字
select studentno,studentname from student
where studentname like '张_'

-- ======in(具体的一个或者多个值)========
-- 查询学号1000,1001的学生
select studentno,studentname from student
where studentno in(1000,1001)
-- 查询在北京的学生
select studentno,studentname from student
where address in('北京朝阳')

-- ========null not null====================
-- 查询地址为空的同学 null或者''
select studentno,studentname from student
where address='' or address is null
-- 查询出生日期不为空的学生
select studentno,studentname from student
where borndate is not null

联表查询

在这里插入图片描述

 -- 查询参加考试的同学(学号,姓名,科目编号,分数)
select * from student
select * from result
/*思路:
1.分析需求:分析查询的字段来自哪些表(连接查询)
2.确定使用哪种连接查询? 7种
  确定交叉点,这两个表中哪些数据是相同的
	判断的条件:学生表的studentno=成绩表 studentno	
*/
select s.studentno,studentname,subjectno,studentresult 
from student as s
inner join  result as r
where s.studentno=r.studentno

-- right join 
select s.studentno,studentname,subjectno,studentresult 
from student as s
right join result as r
on s.studentno = r.studentno

-- left join 
select s.studentno,studentname,subjectno,studentresult 
from student as s
left join result as r
on s.studentno = r.studentno

在这里插入图片描述
练习:

-- ===============联表查询==================
 -- 查询参加考试的同学(学号,姓名,科目编号,分数)
select * from student
select * from result
/*思路:
1.分析需求:分析查询的字段来自哪些表(连接查询)
2.确定使用哪种连接查询? 7种
  确定交叉点,这两个表中哪些数据是相同的
	判断的条件:学生表的studentno=成绩表 studentno	
*/
-- join(连接的表) on(判断的条件) 连接查询
-- where 等值查询
select s.studentno,studentname,subjectno,studentresult 
from student as s
inner join  result as r
where s.studentno=r.studentno

select s.studentno,studentname,subjectno,studentresult 
from student as s
inner join  result as r
on s.studentno=r.studentno

-- right join 
select s.studentno,studentname,subjectno,studentresult 
from student as s
right join result as r
on r.studentno = s.studentno

-- left join 
select s.studentno,studentname,subjectno,studentresult 
from student as s
left join result as r
on s.studentno = r.studentno

-- 查询缺考的同学(只要让成绩为null,就能找到)
select s.studentno,studentname,subjectno,studentresult 
from student as s
left join result as r
on s.studentno = r.studentno where studentresult is null


-- 查询了参加考试的同学信息:学号,学生姓名,科目名称,分数
-- 表 student result subject
-- 右查询
-- 交叉点:学生表 studentno=成绩表 studentno  
--         成绩表 subjectno=科目表 subjectno
select s.studentno,studentname,sub.subjectname,studentresult
from student as s
right join result as r
on r.studentno=s.studentno
inner join `subject` as sub
on r.subjectno=sub.subjectno
-- 我要查询哪些数据 select ...
-- 从哪几个表中查询 from 表 xxx join 连接的表 on 较差条件
-- 假设存在一种多张表查询,先查询两张表开始,然后再慢慢增加
-- from a left join b
-- from a right join b

自连接
自己的表和自己的表连接;

核心:一张表拆分成两张一样的表即可

父类表:
在这里插入图片描述
子类表
在这里插入图片描述查询父类对应的子类关系
在这里插入图片描述

-- 查询父子信息:把一张表看为两个一模一样的表
select a.categoryname as '父栏目',b.categoryname as '子栏目'
from category as a,category as b
where a.categoryid = b.pid

分页和排序

排序

-- 排序:升序 ASC  降序DESC
-- 通过哪个字段排序,怎么排
select s.studentno,studentname,subjectname,studentresult
from student as s
inner join result as r
on s.studentno = r.studentno
inner join `subject` as sub
on sub.subjectno=r.subjectno
where subjectname = '高等数学-1'
order by studentresult DESC

分页

-- 为什么要分页
-- 缓解数据库的压力,给人更好的体验  ---瀑布流
-- 分页,每页显示五条数据
-- 语法:limit 起始值,页面的大小
-- 网页应用:当前页,总页数,页面的大小
-- limit 0,5 1~5条数据
-- limit 1,5 2~6条数据

select * from student limit 0,5
-- 第一页 limit 0,5   (1-1)*5
-- 第二页 limit 5,5   (2-1)*5
-- 第二页 limit 10,5  (3-1)*5
-- 第N页  limit       (n-1)*5
-- pageSize:页面的大小
-- (n-1)*pageSize:起始值
-- n:当前页
-- 数据总数/页面大小=总页数

语法:limit (查询起始下标,pageSize)

子查询

where (值是固定的,这个值是计算出来的)

本质:在where语句中嵌套一个子查询语句

-- 查询高等数学-1的所有考试结果(学号,科目编号,成绩),降序排列
-- 方式1
select studentno,subjectno,studentresult
from result as r
inner join `subject` as sub
on r.subjectno=sub.subjectno
where subjectname='高等数学-1'
order by studentresult DESC
-- 方式2:使用子查询
select studentno,subjectno,studentresult
from result
where subjectno=(
	select subjectno from `subject` 
	where  subjectname='高等数学-1'
)order by studentresult DESC
-- 查询所有高等数学-1的学生的学号
select subjectno from `subject` where subjectname='高等数学-1'

-- 查询分数不小于80分的学生的学号和姓名
select studentno,studentname
from student 
where studentno=(
select distinct studentno from result where studentresult>=80
)
-- 查询课程为高等数学-2并且分数不小于80分的同学的学号和姓名
-- 联表查询
select s.studentno,studentname
from student as s
inner join result as r
on s.studentno=r.studentno
inner join `subject` as sub
on r.subjectno=sub.subjectno
where subjectname='高等数学-2' and studentresult>=80
-- 子查询
select DISTINCT s.studentno,studentname
from student as s
inner join result as r
on s.studentno=r.studentno
where studentresult>=80 and subjectno=(
	select subjectno from `subject` where subjectname='高等数学-2'
)

-- 子查询:(由里及外)
select studentno,studentname
from student where studentno in(
	select studentno from result where studentresult>=80 and subjectno=(
		select subjectno from `subject` where subjectname='高等数学-2'
	)
)
<think>好的,用户想了解RCAB模块在图像超分辨率任务中的作用和原理。首先,我需要回忆一下RCAB的相关知识。RCAB全称是Residual Channel Attention Block,应该是在残差块的基础上加入了通道注意力机制。这通常用于提升超分辨率模型的性能。 记得残差块(Residual Block)在ResNet中被广泛使用,通过跳跃连接缓解梯度消失的问题,帮助训练更深的网络。而通道注意力机制,比如SENet中的Squeeze-and-Excitation模块,能够自动学习各个通道的重要性,增强有用的特征,抑制不重要的。RCAB可能结合了这两者。 接下来,需要确认RCAB的具体结构。根据常见的设计,RCAB可能包含多个卷积层,然后是通道注意力模块,最后通过残差连接相加。这样可以在提取特征的同时,动态调整各通道的权重,让网络更关注重要的信息。 在超分辨率任务中,RCAB的作用应该是增强高频细节的恢复,比如边缘和纹理,这对于提升图像清晰度至关重要。同时,通道注意力机制能有效利用通道间的依赖关系,优化特征表达,从而提升重建质量。 应用场景方面,RCAB可能被用于如EDSR、RCAN等超分辨率模型中。这些模型通常堆叠多个RCAB模块,通过深层的网络结构逐步恢复高分辨率图像。特别是在处理大倍数超分辨率(如4x、8x)时,RCAB能帮助保持细节,减少模糊。 还需要考虑RCAB的优势。比如,通过残差学习简化了优化过程,而通道注意力则增强了特征的区分能力。这可能使得模型在计算资源有限的情况下仍能保持高效,同时提升性能。 需要验证这些信息是否正确。参考用户提供的资料,引用[1]提到多尺度卷积和特征融合,引用[2]提到信息交互和注意力机制。虽然没有直接提到RCAB,但通道注意力属于注意力机制的一种,符合引用中的信息。因此可以推断RCAB的应用场景这些模块类似,用于特征提取和优化。 总结来说,RCAB的作用是通过残差结构和通道注意力机制,有效提取并优化特征,提升超分辨率重建的质量。应用场景包括各种基于深度学习的超分辨率模型,特别是在需要恢复细节和高效利用特征时。</think>RCAB(Residual Channel Attention Block)模块在图像超分辨率任务中主要用于**增强特征表达能力并优化高频细节恢复**,其核心原理是通过残差学习通道注意力机制的结合,动态调整特征通道的重要性权重。 ### 作用原理分步说明: 1. **残差学习框架** RCAB基于残差块(Residual Block)设计,包含两个卷积层和激活函数,通过跳跃连接(Skip Connection)将输入输出相加。这种方式缓解了梯度消失问题,支持更深的网络训练,公式为: $$F(x) = H(x) + x$$ 其中$H(x)$为残差函数,$x$为输入特征。 2. **通道注意力机制** 在残差块后引入通道注意力模块(Channel Attention Module),通过全局平均池化(Global Average Pooling)统计通道特征,并利用全连接层生成通道权重: $$w_c = \sigma(W_2 \cdot \delta(W_1 \cdot \text{GAP}(x)))$$ 其中$\sigma$为Sigmoid函数,$\delta$为ReLU,$W_1$和$W_2$为全连接层参数。最终输出特征为各通道加权后的结果: $$x' = w_c \cdot x$$ 该机制使网络自动关注对重建更重要的特征通道[^1]。 3. **多尺度特征融合** RCAB常多尺度特征提取模块结合(如引用[1]中提到的多尺度卷积层),通过不同感受野的卷积核捕获低频和高频信息,再利用通道注意力筛选关键特征,减少冗余计算,提升重建效率。 ### 应用场景 - **单图像超分辨率(SISR)**:如RCAN(Residual Channel Attention Networks)模型,通过堆叠多个RCAB模块恢复高分辨率图像的细节[^2]。 - **多模态超分辨率融合**:在红外可见光图像融合任务中,RCAB用于增强跨模态特征的表征能力,保留边缘和纹理信息[^1]。 - **轻量超分辨率网络**:由于通道注意力可抑制无效特征,RCAB在减少计算量的同时保持性能,适用于移动端部署。 ### 示例模型结构 ```python class RCAB(nn.Module): def __init__(self, channels): super().__init__() self.conv1 = nn.Conv2d(channels, channels, 3, padding=1) self.conv2 = nn.Conv2d(channels, channels, 3, padding=1) self.ca = ChannelAttention(channels) # 通道注意力模块 def forward(self, x): res = self.conv1(x) res = F.relu(res) res = self.conv2(res) res = self.ca(res) # 通道加权 return x + res # 残差连接 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小冻梨♬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值