sql数据库查询语句和查询条件where

我来纠错
//查询name是安云大神的数据,select * 的意思就是查询所有字段值,也可以指定某几个字段用英文逗号隔开,例如:name,mobile
select * form tablename where name='安云大神';

//or(或者)、and(和),多条件查询。and优先级比or高,如果要改变优先级,可以用小括号包起来。
select * form tablename where name='安云大神' or name='前端机器人';
select * form tablename where name='安云大神' and mobile='15888888888';
select * form tablename where (name='安云大神' or name='前端机器人') and mobile='15888888888';

//in,多条件查询同一个字段可以用in来查询,效率比or高。
select * form tablename where name='安云大神' or name='前端机器人';
等同于
select * form tablename where name in ('安云大神','前端机器人');

//not,查询不包含的数据
select * form tablename where not name='安云大神';

//between,查询指定两个值之间得数据,例如,查询age字段值在20-30之间的数据
select * form tablename where age between 20 and 30;

//is null,查询为空的数据
select * form tablename where age is null;

//like,(%匹配任意字符任意次数,_匹配一个字符)查询模糊匹配得字段值。
select * form tablename where name like '%安云%';  //查询name值包含安云的数据,前后所有字符串不限。
select * form tablename where name like '%安云_';  //查询name值包含安云的数据,前面字符串不限,后面字符串只有一位不限  
发送
热门关键词:
命令
知识类型:
标题描述:
详细解答:

提交审核您编辑的知识会经过 前端大牛 人工审核。