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

您所在的位置:网站首页 sqlserver连表查询含义 SQL查询(模糊查询,连接查询,多表查询)

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

2024-07-05 21:08| 来源: 网络整理| 查看: 265

模糊查询:

用于处理字符串类型的值,运算符包括: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


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3