1、where条件子句
作用:检索数据库中符合条件的值
逻辑运算符:
and && a&&b ,a and b
or || a||b ,aorb
not ! not a , !a
2、模糊查询
比较运算符:
is noll//如果为空,则为真
is not null//如果不为空,则为真
between and//在a 和 b 之间,则为真
例:
select * from student where 成绩 between 95 and 100;//成绩在95到100之间
like //a like b 如果a匹配b,则为真
例:有两种为'%',代表0或者任意个字符,'_'代表一个字符
select * from student where name like '华%';//查询姓华的同学
select * from student where name like '%华%';//查询名字中带有'华'字的同学
select * from student where name like '华_';//查询姓华的同学,名字后面只有一个字的
in //a in (a1,a2,a3),满足其中一个,则为真
例:
select * from student where id in (1,2,3);//查询编号在1,2,3其中一个
3、联表查询
左查询:left join
右查询:right join
自连接:inner join
| 操作 | 描述 |
|---|---|
| inner join | 如果表中至少有一个表匹配就返回结果 |
| left join | 会从左表中返回结果,即使右表中没有匹配的数据 |
| right join | 会从右表中返回结果,即使左表中没有匹配的数据 |
4、自连接
自己的表和自己的表连接,核心:一张表拆为两张一样的表即可
版权声明:本文为qq_39379958原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。