长丰县住房和城乡建设局网站,个人网页完整代码,建设网站一定要电脑吗,东莞做网站公司首选第六章 - 数据过滤#xff08;where的用法#xff09;基本用法where的条件限制符等于号不等号! 或者小于大于小于等于大于等于between 的用法空值和非空值组合条件 and组合条件 orand 和 or 的计算次序in 和 not in基本用法
在查询语句中#xff0…
第六章 - 数据过滤where的用法基本用法where的条件限制符等于号不等号! 或者小于大于小于等于大于等于between 的用法空值和非空值组合条件 and组合条件 orand 和 or 的计算次序in 和 not in基本用法
在查询语句中可以根据需要使用where语句来对指定搜索条件进行过滤得到需要的数据where语句在from语句之后使用。
# 查询售价大于600000的数据
selectSalePrice
fromtest.houseprices
whereSalePrice 600000where的条件限制符
等于号
只查询displayName 字段内等于Michael Carter的数据
selectdisplayName,weight,nflId
fromnfl.players
where# 此处Michael Carter可以使用单引号 或者双引号 表示str字符串格式displayName Michael Carter 不等号! 或者
查询性别不为’male‘的数据
select*
fromtest.titanic
where# 或者 sex male 表示的意义是一样的sex ! male小于
查询年龄小于10岁的数据比10小的数不包含10
select*
fromtest.titanic
whereage 10大于
查询年龄大于 岁的数据
select*
fromtest.titanic
whereage 60小于等于
查询小于等于6岁的用户数据不大于6的数包含6.
select
*
from
test.titanic
where
age 6大于等于
查询小于等于60岁的用户数据不小于60的数包含60.
select*
fromtest.titanic
whereage 60between 的用法
查询年龄在50到54岁之间的数据between是包含50和54这两个值的。
select*
fromtest.titanic
whereage between 50 and 54空值和非空值
一般数据库内空值的数据都用null来填充也有用’-999‘当用null来填充空值的时候就可以直接使用此语句来筛选。用其他数据值填充的可以直接用等于和不等于!来筛选
完整数据带有null。
筛选age为null的数据 select
*
from
test.test001
where
age is null筛选age不是null 的数据 select*
fromtest.test001
whereage is not null组合条件 and
进行多条件筛选时可以使用and给where语句添加多个条件。and表示筛选条件要同时满足也就是“和”的意思。下面例子表示查询同时满足 sex male 和 age 60 条件的数据。 selectname,sex,age,fare
fromtest.titanic
wheresex male and age 60 组合条件 or
进行多条件筛选时也可以使用 or 给 where 语句添加多个条件or 表示满足其中一个即可也就是“或”的意思。下面例子和上面用同样的数据只是把条件and变为or数据量明显要多很多因为只要满足sexmale或者age60其中一个条件就可以条件限制更宽松一些 selectname,sex,age,fare
fromtest.titanic
wheresex male or age 60 and 和 or 的计算次序
下面例子可以看到我们想要的结果是要满足age40或者age60这两个条件且满足fare50需要fare都大于50。但是输出结果后面的四行数据age40都是fare是小于50的和想要的结果不一样。这是因为and在计算次序中的优先级高于or系统会先计算and然后再计算or。 select
name,
sex,
age,
fare
from
test.titanic
where
age 40 or age 60 and fare 50解决这种问题的方法用括号来明确分组相应的操作符因为括号的计算优先级要高于and和or具体如下执行时会优先计算括号内的条件然后再计算括号外的条件 selectname,sex,age,fare
fromtest.titanic
where(age 40 or age 60) and fare 50in 和 not in
in用来指定条件范围范围中的每个条件都可以进行匹配in的取值全部都再括号中由逗号分隔当取值为字符时需要用引号单/双引号 都可以来表示字符例如(Jack,小明)in与or条件的功能是相同的用的代码更少且执行速度更快。
selectname,sex,age,fare
fromtest.titanic
where# 表示 满足 age50 或者 age55age in (50,55) not in 表示否定后面的条件如上面例子把in 改为not in 就表示所有age不是50或者55的数据。
selectname,sex,age,fare
fromtest.titanic
whereage not in (50,55)