sql where 子句
where 子句用于规定选择的标准。
如需有条件地从表中选取数据,可将 where 子句添加到 select 语句。语法如下:
select 列名称 from 表名称 where 列 运算符 值
下面的运算符可在 where 子句中使用:
=:等于
<>:不等于
>:大于
<:小于
>=:大于等于
<=:小于等于
between:在某个范围内
like:搜索某种模式
注释:在某些版本的 sql 中,操作符 <> 可以写为 !=。
使用 where 子句
如果只希望选取居住在城市 "beijing" 中的人,我们需要向 select 语句添加 where 子句:
select * from persons where city="beijing"
"persons" 表
lastname firstname address city yearadams john oxford street london 1970bush george fifth avenue new york 1975carter thomas changan street beijing 1980gates bill xuanwumen 10 beijing 1985
结果:
lastname firstname address city yearcarter thomas changan street beijing 1980gates bill xuanwumen 10 beijing 1985
引号的使用
sql 使用单引号来环绕文本值(大多数据库系统也接受双引号)。如果是数值,则不使用引号。
select * from persons where firstname="bush"select * from persons where year>1965
以上就是sql中如何使用where子句规定选择的标准的详细内容。
