常用的查询条件
SQL(三)——where子句

比较

“=”、“<”、“>”、“<=”、“>=”、“!=”、“!>”、“!<”、“not + 运算符”

select distinct sname
from student
where sdept='cs'

多重条件

“and”、“or”、“not”

select distinct sname
from student
where sage>20 and sdept='cs'

确定范围

“between and”、“not between and”,范围是闭区间

select distinct sname, sage
from student
where sage between 20 and 21

确定集合

“in()”、“not in()”
用 “in()” 可以用来查找属性值属于指定集合的元组

select distinct sname, sage
from student
where sdept in('cs','is')

字符匹配

通配符“%”

“%”可匹配任意长度的字符串

select distinct sname, sage
from student
where sname like '爱%青菜'

通配符“_”

“_”代表任意单个字符

select distinct sname, sage
from student
where sname like '王_'

SQL(三)——where子句

‘’

这是MySQL的写法,和java转义一样

select distinct sname, sage, sdept
from student
where sdept like 'cs\_%'

SQL(三)——where子句

空值查询

“is null”、“is not null”

select distinct sname, sage, sdept
from student
where sage is null

相关文章:

  • 2021-11-28
  • 2022-12-23
  • 2022-01-18
  • 2021-12-25
  • 2022-12-23
  • 2021-08-19
猜你喜欢
  • 2021-03-31
  • 2022-01-27
  • 2022-01-13
相关资源
相似解决方案