SQL查询(模糊查询,连接查询,多表查询)

模糊查询:

用于处理字符串类型的值,运算符包括:like%_[]^%与_写在[]中表示的含义
根据字符查找(%表示左右的字符),名字当中包含懒狗的信息
select * from StudentInfo where Name like '%懒狗%'
查询姓孙的信息

select * from StudentInfo
where Name like '孙%'

查询名字为3个字叫孙笑*的

select * from StudentInfo
where sName like '孙笑_'

查询消费超过8000段的学生信息(低于9000)

select *from StudentInfo
where sPrice like '8[000-999]'

查询消费非8000段的学生(低于9000)

select * from StudentInfo
where Price like '^8[000-999]'

查询母亲为null的学生信息

select * from StudentInfo
where Mum is null

连接查询
join 表名 on 关联条件
内连接:inner join,两表中完全匹配的数据
左外连接: left outer join, 两表中完全匹配的数据,左边中特有的数据
右外连接: right outer join, 两表中完全匹配的数据,右边中特有的数据
完全外连接: full outer join
查询两表的学生与他母亲的名字

select * a.Name,b.Mum
from StudentInfo as a
inner join ClassInfo as b on a.id = b.id 

查询两表的学生与他母亲的名字,其中学生名字为孙笑川

select * a.Name,b.Mum
from StudentInfo as a
inner join ClassInfo as b on a.id = b.id 
where a.Name = '孙笑川'

查询左(前)另一张表特有的数据(包括共有的)

select * 
from ClassInfo as a left join StudentInfo as b on a.id= b.id

查询右(后)一张表特有的数据(包括共有的)

select * 
from ClassInfo as a right join StudentInfo as b on a.id= b.id

重复数据只显示一次

select * 
from ClassInfo as a full join StudentInfo as b on a.id= b.id

多表查询

select *
from ScoreInfo as a
inner join StudentInfo as b on a.stuid = b.id
inner join SubjectInfo as c on a.subid = c.id
inner join ClassInfo as d on b.id = d.stuid
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值